/////////////////////////// PAGE LOADER GRAPHIC
function contentLoaded() {
	$("div#loaderContainer").hide();
	$("div#ContentContainer").fadeIn("slow");
}

$(document).ready(function () {

	/////////////////////////// SET-UP FOR TEXT ROLLOVER FADE EFFECT
	$(function(){
		$(".fademe").jFade({
			trigger: "mouseover",
			property: 'color',
			start: '333333',
			end: '999999',
			steps: 12,
			duration: 12
		}).jFade({
			trigger: "mouseout",
			property: 'color',
			start: '999999',
			end: '333333',
			steps: 12,
			duration: 12
		});
		$(".shirtImage").jFade({
			trigger: "mouseover",
			property: 'background',
			start: 'FFFFFF',
			end: 'FFD53A',
			steps: 9,
			duration: 9
		}).jFade({
			trigger: "mouseout",
			property: 'background',
			start: 'FFD53A',
			end: 'FFFFFF',
			steps: 9,
			duration: 9
		});				
	});
	
	/////////////////////////// LOGO ROLLOVER FADE
	$('h1#logo a').hover(
		function() {
			$(this).stop().fadeTo(250, 0.70);
		},
		function() {
			$(this).stop().fadeTo(300, 1);
		}
	);
	
	/////////////////////////// LEFT COL ROLLOVER EFFECT
	$("#colLeft").fadeTo("100", 0.25);
	
	$("#colLeft").hover(
		function () {
		$(this).stop().fadeTo("200", 1);
	  }, 
		function () {
	    $(this).stop().fadeTo("200", 0.25);
	  }
	);
	
    /////////////////////////// FORM: CONTACT PANEL
    $('#contactForm').ajaxForm(function(data) {
	    if (data==1){
	    	$('#successContact').fadeIn("slow");
	        $('#bademailContact').fadeOut("slow");
	        $('#contactForm').resetForm();
	        $('#contactForm').hide();
	    }
	    else if (data==2) $('#badserverContact').fadeIn("slow");
	    else if (data==3) {
	        $('#bademailContact').fadeIn("slow");
	        $('#contactFormEmail').focus();
	    }
    });
    /////////////////////////// FORM: NEWSLETTER SIGNUP
    $('#newsletterSignup').ajaxForm(function(data) {
	    if (data==1){
	    	$('#successNewsletter').fadeIn("slow");
	        $('#bademailNewsletter').fadeOut("slow");
	        $('#newsletterSignup').resetForm();
	        $('#newsletterSignup').hide();
	    }
	    else if (data==2) $('#badserverNewsletter').fadeIn("slow");
	    else if (data==3) {
	        $('#bademailNewsletter').fadeIn("slow");
	        $('#newsletterSignupEmail').focus();
	    }
    });
    /////////////////////////// FORM: ANTI-SPAM
    $.get("http://www.bagofbees.co.uk/blog/wp-content/themes/bob/token.php",function(txt){
	  $(".secure").append('<input type="hidden" name="ts" value="'+txt+'" />');
	});

	// ADD MAIN BODY SCROLLBAR
	var isResizing;
	
	// ADD MAIN BODY SCROLLBAR
	var isResizing;
	
	// and the body scrollpane
	var setContainerHeight = function()
	{
		// IE triggers the onResize event internally when you do the stuff in this function
		// so make sure we don't enter an infinite loop and crash the browser
		if (!isResizing) { 
			isResizing = true;
			$w = $(window);
			$c = $('#scrollContainer');
			var p = (parseInt($c.css('paddingLeft')) || 0) + (parseInt($c.css('paddingRight')) || 0);
			$c.css({'height': ($w.height()-p) + 'px', 'width': ($w.width() - p) + 'px'});
			isResizing = false;	
			//CSBfleXcroll('scrollContainer');
		}
	}
	$(window).bind('resize', setContainerHeight);
	// reset scroll bar once images loaded
	$(window).bind('load', setContainerHeight);
	setContainerHeight();
	
	// it seems like you need to call this twice to get consistantly correct results cross browser...
	setContainerHeight();
	// END ADD MAIN BODY SCROLLBAR
	
	/////////////////////////// BACK TO TOP ANIMATE		
	$('.backToTop, .backToTopPost').click(function(){
		 //$('#scrollContainer')[0].scrollTo(0);
		 $('body').scrollTo( { top:0 , left:0}, 700, {easing:'easeInOutCubic'});
	     return false;
	});
	
	/////////////////////////// CONTACT PANEL SETUP
	$("#contactPanel").animate({ 
    	height: "0px",
    	opacity: 0
    }, 0 );
    
    $(".contactPanelContent").fadeOut();
    //$(".contactPanelContent").css({"display":"block"});
	var contactPanelHidden = true;
	var contactPanelShowing;
	var hasClosed;

	
	$(".addLink.contactPanelLink").click(function(){
		///$('#scrollContainer')[0].scrollTo(0);
		//$('#scrollContainer').scrollTo( { top:0 }, 1000, {easing:'easeInOutCubic'});
		
		 $('body').scrollTo( { top:0 , left:0}, 1000, {easing:'easeInOutCubic'});
	});

	$(".contactPanelLink").click(function(){
		var targetPane = $(this).attr('href');
		
		
		
		if(contactPanelHidden != true){
			$('.contactPanelLink').removeClass('selected');
      		$("#contactPanel").animate({ 
				height: "0px",
				opacity: 0
      		}, 500, function(){
      			setContainerHeight();	
      		});
      		$(".contactPanelContent").fadeOut(500);
      		hasClosed = true;
		}
			
			
		if(contactPanelShowing != targetPane || contactPanelHidden == true) {
			contactPanelShowing = targetPane;
			$(this).addClass('selected');
			
			//$('div' + targetPane).fadeIn(500);
			$('div' + targetPane).animate({ 
				opacity: 1
			}, 500, function(){	
				$('div' + targetPane).fadeIn(500);
      			setContainerHeight();	
			});

			
		 	$('body').scrollTo( { top:0 , left:0}, 1000, {easing:'easeInOutCubic'});
			$("#contactPanel").animate({ 
				opacity: 1
			}, 0 );
      		$("#contactPanel").animate({ 
				height: "300px",
				opacity: 1
      		}, 500, function(){
    			setContainerHeight();
      		});
      		hasClosed = false;
		}
		
		
		contactPanelHidden = hasClosed;
		
		return false; 
    });

});