var tabssetup = false;



function setup_tabs()
{


    //tabs in teacher zone
    if( $.browser.msie == false ){
        $("ul#tabs").tabs( "#panes > div", { history: true } );
    }else{
        $("ul#tabs").tabs( "#panes > div", { history: false } );
    }
    


    $("#panes h2").hide();



    $('#tabs a:not(".active")').hover(function () {
            $(this).children().attr("src", $(this).children().attr("src").replace(/-off.png/, "-on.png"));
    },function () {
            $(this).children().attr("src", $(this).children().attr("src").replace(/-on.png/, "-off.png"));
    });

    $('#tabs a').click(function() {
            $('#tab-1 img').attr("src", $('#tab-1 img').attr("src").replace(/-on.png/, "-off.png"));
            $('#tab-2').children('img').attr("src", $('#tab-2').children('img').attr("src").replace(/-on.png/, "-off.png"));
            $('#tab-3').children('img').attr("src", $('#tab-3').children('img').attr("src").replace(/-on.png/, "-off.png"));
            $('#tab-1').children('img').attr("src", $('#tab-1').children('img').attr("src").replace(/-now.png/, "-off.png"));
            $('#tab-2').children('img').attr("src", $('#tab-2').children('img').attr("src").replace(/-now.png/, "-off.png"));
            $('#tab-3').children('img').attr("src", $('#tab-3').children('img').attr("src").replace(/-now.png/, "-off.png"));
            $('#tabs a').removeClass('active');
            $(this).children().attr("src", $(this).children().attr("src").replace(/-off.png/, "-now.png"));
            $(this).addClass('active');
    });

    //check for hash in url when in 'teacher zone'
    //setTimeout(function() { $('#foo').fadeOut(); }, 5000);

    window.setTimeout(function() {
        if ($("#tabs").length > 0){
            if ($(".filtered").length > 0){
                    window.location.hash = '#t2';
                    $('#tab-2').trigger('click');
            } else if(window.location.hash) {
                    hash = window.location.hash;
                    if(hash == '#t1'){
                            $('#tab-1').trigger('click');
                    }else if(hash == '#t2'){
                            $('#tab-2').trigger('click');
                    }else if(hash == '#t3'){
                            $('#tab-3').trigger('click');
                    }else if(hash == '#'){
                            $('#tab-1').trigger('click');
                    }
            } else {
                    window.location.hash='#t1';
                    $('#tab-1').trigger('click');
            }

        }
    }, 1000);

    //select replacement - uses jquery.selectbox-0.6.1.js
    $('.filter select').sSelect();
    $('.filter label').hide();

    //newsletter toggle
    $('#newsletter:not(.dont-hide)').hide();

    $('#newsletter-toggle').click(function() {
            $('#newsletter').slideToggle();
    });

    $('#feedback-toggle').click(function() {
            $('#feedback, #newsletter:visible').slideToggle();
    });

    $('#newsletter.dont-hide').show();

    tabssetup = true;
    return true;
}








$(document).ready(function() {

	$('a[rel="external"]').click(function(){
		window.open(this.href);
		return false;
	});

	//get cookie for background color and flash - uses jquery.cookies.2.2.0.min.js
	var jazzy = $.cookies.get( 'jazzy' );
	
	// Drip on last section
	if ($('.long').length != 0  && $('.section').size() > 5 ){
            // there is a long one and there is more than 5
            $('.section:last').append('<span class="drip"></span>');
	}else if( $('.long').length != 0 && $('.section').size() < 6 ){
            // ther is a long one, total is less than 6 so put it on the longun
            $('.long').append('<span class="drip"></span>');
	}else{
            $('.section:last').append('<span class="drip"></span>');

        }
        
        if(  $('.section').size() ==5 || $('.section').size() ==8 ){
        }
        else{
            $('.drip').hide();
        }


		






	
	
	//animation containers
	$('#wrapper').prepend('<span id="sparkle"></span><span id="rocket"></span><span id="rocket-1"></span><span id="carousel"></span><span id="bubble"></span><span id="bubble-1"></span>');
	
	//flashembed - uses toolbox.flashembed.min.js
	//flashembed("flash", {src: "/wp-content/themes/jazzy/flash/games/design-a-habitat/PLAY.swf", wmode: 'transparent'});
	
	flashembed("sparkle", {src: "/wp-content/themes/jazzy/flash/leftStars.swf", wmode: 'transparent'});
	flashembed("rocket", {src: "/wp-content/themes/jazzy/flash/rocketLarge.swf", wmode: 'transparent'});
	flashembed("rocket-1", {src: "/wp-content/themes/jazzy/flash/rocketSmall.swf", wmode: 'transparent'});
	flashembed("carousel", {src: "/wp-content/themes/jazzy/flash/carousel.swf", wmode: 'transparent'});
	flashembed("bubble", {src: "/wp-content/themes/jazzy/flash/rightBubbGreen.swf", wmode: 'transparent'});
	if (jazzy == "orange"){
		flashembed("bubble-1", {src: "/wp-content/themes/jazzy/flash/bottomBubbOrange.swf",	wmode: 'transparent'});
		$('#header h1 img').attr("src","/wp-content/themes/jazzy/images/design/logo-orange.png" );
	} else if (jazzy == "purple"){
		flashembed("bubble-1", {src: "/wp-content/themes/jazzy/flash/bottomBubbPurple.swf",	wmode: 'transparent'});
		$('#header h1 img').attr("src","/wp-content/themes/jazzy/images/design/logo-purple.png" );
	} else if (jazzy == "yellow"){
		flashembed("bubble-1", {src: "/wp-content/themes/jazzy/flash/bottomBubbYellow.swf",	wmode: 'transparent'});
		$('#header h1 img').attr("src","/wp-content/themes/jazzy/images/design/logo-yellow.png" );
	} else if (jazzy == "blue"){
	  	flashembed("bubble-1", {src: "/wp-content/themes/jazzy/flash/bottomBubbBlue.swf",	wmode: 'transparent'});
		$('#header h1 img').attr("src","/wp-content/themes/jazzy/images/design/logo-blue.png" );
	} else{
		flashembed("bubble-1", {src: "/wp-content/themes/jazzy/flash/bottomBubbGreen.swf",	wmode: 'transparent'});
		$('#header h1 img').attr("src","/wp-content/themes/jazzy/images/design/logo-green.png" );
	}
	$('#bubble-1').hide().show();
	//background switcher - uses jquery.cookies.2.2.0.min.js
	(function(){
		$('#header').append('<div class="bg-picker"><p>Choose your colour</p><ul><li><a href="#na" id="orange">Orange</a></li>	<li><a href="#na" id="purple">Purple</a></li><li><a href="#na" id="yellow">Yellow</a></li><li><a href="#na" id="blue">Blue</a></li><li><a href="#na" id="green">green</a></li></ul></div>')
		
		$('body').addClass(jazzy);
		
		$('.bg-picker a').click(function() {
  			var bg = $(this).attr('id');
			$.cookies.set( 'jazzy', bg );
			location.reload();
		});
		
	})();

	// Section hover
	$('.section:not(.teacher)').hover(
		function () {
			$(this).addClass('on');
		}, 
		function () {
			$(this).removeClass('on');
		}
	);
	
	// section hover css
	$('.section:not(.teacher)').hover(
		function () {
			$(this).css('background-position','-240px bottom');
			$(this).children('.top').css('background-position','-240px top');
		}, 
		function () {
			$(this).css('background-position','bottom left');
			$(this).children('.top').css('background-position','top left');
		}
	);
	
	// section two-thirds hover css
	$('.section.two-thirds').hover(
		function () {
			$(this).css('background-position','-420px bottom');
			$(this).children('.top').css('background-position','-420px top');
		}, 
		function () {
			$(this).css('background-position','bottom left');
			$(this).children('.top').css('background-position','top left');
		}
	);
	
	// section third hover css
	$('.section.third').hover(
		function () {
			$(this).css('background-position','-320px bottom');
			$(this).children('.top').css('background-position','-320px top');
		}, 
		function () {
			$(this).css('background-position','bottom left');
			$(this).children('.top').css('background-position','top left');
		}
	);
	
	// section media hover css 
	$('.section.media').hover(
		function () {
			$(this).css('background-position','-660px bottom');
			$(this).children('.top').css('background-position','-660px top');
		}, 
		function () {
			$(this).css('background-position','bottom left');
			$(this).children('.top').css('background-position','top left');
		}
	);
	
	// section full hover css 
	$('.section.full').hover(
		function () {
			$(this).css('background-position','-760px bottom');
			$(this).children('.top').css('background-position','-760px top');
			$(this).children('.inner').children('.top').css('background-position','-760px top');
		}, 
		function () {
			$(this).css('background-position','left bottom');
			$(this).children('.top').css('background-position','left top');
			$(this).children('.inner').children('.top').css('background-position','left top');
		}
	);
	
	
	
	$('#footer li:last-child').addClass('end');


        setup_tabs();


});


$(document).ready(function(){

    if( tabssetup != true ){

        setup_tabs();
        // Sometimes IE doenst do this properly, so check if its done and if not, have another go!
    }

});


    









