/* ===========================================================================
 * Filename: javascript/functions.js
 * Author: Rebecca Skeers, rebecca@webmistress.com.au, www.webmistress.com.au
 * Copyright: Rebecca Skeers except where noted
 * Date: 21 June 2009
 * Description: Contains javascript functions for the Plane Tree Studio website.
 *
 * This file may not be used for any purpose other than for the Plane Tree Studio
 * website and may not be modified without written permission from the author.
 * =========================================================================== 
 */

$(document).ready(function()
{	
	$("a[rel='external']").attr("target","_blank");
	
	$("li > a.pdf").parent().parent().addClass("nobullet");
	$("li > a.doc").parent().parent().addClass("nobullet");
	$("li > a.xls").parent().parent().addClass("nobullet");
	$("li > a.ppt").parent().parent().addClass("nobullet");
	
	$("#nav li > ul").parent().addClass("haschildren");
	
	$("div.image-left > p > img").each(function() { $(this).parent().parent().width($(this).attr("width")); });
	$("div.image-right > p > img").each(function() { $(this).parent().parent().width($(this).attr("width")); });
	$("div.image-left > img").each(function() { $(this).parent().width($(this).attr("width")); });
	$("div.image-right > img").each(function() { $(this).parent().width($(this).attr("width")); });
	
	$('a.lightbox').lightBox();
	
	$("hr").wrap("<div class=\"hr\"></div>");
	
	$("#footerinfo p:first-child").addClass("first");
	$("#footerinfo p:last-child").addClass("last");
});



$(document).ready(function()
{	
	/*
	$("#navigation li ul").hide(); 
	*/
	$(".thumbnails li").hover(
		function () 
		{
			$(this).addClass("hover");
		},
		function()
		{
			$(this).removeClass("hover");
		}
	);//hover
	
});




/* Google map functions */
$(window).resize(function()
{
	if(typeof loadMap==='function')
		loadMap();
});

$(window).unload(function()
{
	if(typeof GUnload==='function')
		GUnload();
});

$(document).ready(function()
{
	if(typeof loadMap==='function')
		loadMap();
});





/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch() {
    var $active = $('#slideshow img.active');

    if ( $active.length == 0 ) $active = $('#slideshow img:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow img:first');

    // uncomment the 3 lines below to pull the images in random order
    
     var $sibs  = $active.siblings();
     var rndNum = Math.floor(Math.random() * $sibs.length );
     var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});