document.write('<style type="text/css">img { -moz-opacity:.0; filter:alpha(opacity=0); opacity:.0; } body { overflow: hidden }</style>');

function selectorImagesLoaded($selector){ 
    $('img').animate({ 
	opacity: 1
	}, 200 );
} 

setTimeout("selectorImagesLoaded()",2000);


$(document).ready(function () {
	
	/*
	// 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);
			$('body>.jScrollPaneContainer').css({'height': $w.height() + 'px', 'width': $w.width() + 'px'});
			$c.css({'height': ($w.height()-p) + 'px', 'width': ($w.width() - p) + 'px', 'overflow':'auto'});
			$c.jScrollPane({scrollbarWidth:12, animateTo:true, animateInterval:40});
			isResizing = false;	
		}
	}
	$(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
	*/
	
	$('#love ul.linkList').jScrollPane();
	$('#shops ul.linkList').jScrollPane();
	$('#source ul.linkList').jScrollPane();
	
	//$("img").lazyload();
	
	// 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);
			$('body>.flexcroll').css({'height': $w.height() + 'px', 'width': $w.width() + 'px'});
			$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
	
	/////////////////////////// FGC
	
	$('#gear-calc-form').submit(function(){
								
				$('#gear-chart-content').html("");
				$('#chainring-size option:selected').each(function(){
					curchainring = $(this).val();
					$('#cog-size option:selected').each(function(){
						
						var str = curchainring + ' | ' + $(this).val() + "\n";
						var htmlstr = "<tr><td>" + curchainring + "</td><td>" + $(this).val() + "</td>";
						var gc = new GearCalc($('#wheel-size').val(), curchainring, $(this).val(), $('#ambiskidder:checked').val());
						str += "Ratio: " + gc.calcRatio() + "\n";
						str += "Inches: " + gc.calcInches() + "\n";
						str += "Skid Patches: " + gc.calcSkidPatches() + "\n";        		
						
						
						htmlstr += "<td>" + gc.calcInches().toFixed(2) + "</td>";
						htmlstr += "<td>" + gc.calcRatio().toFixed(2) + "</td>";
						htmlstr += "<td>" + gc.calcSkidPatches() + "</td>";
						htmlstr += "</tr>";			
						//alert(str);
						$('#gear-chart-content').append(htmlstr);
					});	       
				});
				
				var i=0;
				$('#gear-chart-content tr:even').each(function(){$(this).addClass("even");});
				
				return false;
			});

	/////////////////////////// TAGS LIST ANIMATE
	
	$(".tagscol li").css({"display":"block"});
	
	//if($.cookie('tags_open') != 'true') {
		$(".tagscol").animate({ 
			width: "0px",
			opacity: 0
		}, 0 );
		
   		$(".tagscol ul").css({"display":"none"});
		var tagsHidden = true;
	/*} else {
   		$(".tagscol ul").css({"display":"block"});
		$(".tagscol").animate({ 
			width: "120px",
			opacity: 1
		}, 0 );
		$("#header").animate({ 
			marginLeft: "120px"
		}, 0 );
		var tagsHidden = false;	
	}*/
	
	
	$("#tagsTitle").click(function(){
		if(tagsHidden == true){
			tagsHidden = false;
   			$(".tagscol ul").css({"display":"block"});
			$(this).addClass('selected');
			$(".tagscol").animate({ 
				width: "120px",
				opacity: 1
			}, 500 );
			$("#header").animate({ 
				marginLeft: "120px"
			}, 500 );
			//$.cookie('tags_open', 'true');
		} else {
			tagsHidden = true;
			$(this).removeClass('selected');
			$(".tagscol").animate({ 
				width: "0px",
				opacity: 0
			}, 500, function(){
				
   				$(".tagscol ul").css({"display":"none"});	
			} );
			$("#header").animate({ 
				marginLeft: "0px"
			}, 500 );
			//$.cookie('tags_open', 'false');
			
		}
		return false;
	});
	
	
	
	/////////////////////////// BACK TO TOP ANIMATE	
	
	$('.backToTop').click(function(){
		 //$('#scrollContainer')[0].scrollTo(0);
		 $('body').scrollTo( { top:0 , left:0}, 1000, {easing:'easeInOutCubic'});
         return false;
	});
	
	
	/////////////////////////// FORM SHIZZLE	
	
	$('.textBox').focus(function(){
		thisTitle = $(this).attr('title');
		thisVal = $(this).attr('value');
		if(!thisTitle || thisTitle == thisVal) {
			thisVal = $(this).attr('value');
			$(this).attr('title',thisVal);
			this.value = '';
		}
	});
	$('.textBox').blur(function(){
		if(this.value == '' || this.value == ' '){
			thisVal = $(this).attr('title');
		 	this.value = thisVal;
		}
	});


	$("#commentform .submit").click(function(){	
		$("#commentform .textBox" ).each(function(){
			var thisVal = $(this).attr('title');
			if(this.value == thisVal){
			 	this.value = "";
			}
		});
		return true;
	});


	/////////////////////////// TOOL TIPS ANIMATE	
	
//	$('a').tooltip({ 
//		track: true, 
//		delay: 600, 
//		showURL: false, 
//		opacity: 0.85, 
//		fixPNG: true,
//		extraClass: "pretty fancy",
//		top: -20, 
//		left: 20 
//	});
	
	

	/////////////////////////// CAROUSEL	
	
	
	$("#eventsCarousel .carousel.over").jCarouselLite({
		btnNext: "#eventsCarousel .next",
		btnPrev: "#eventsCarousel .prev",
		visible: 1,
		circular: true,
		easing: 'easeInOutCubic',
		speed: 800
	});
	
	$("#eventsCarousel .carousel.under").jCarouselLite({
		btnNext: "#eventsCarousel .next",
		btnPrev: "#eventsCarousel .prev",
		visible: 1,
		circular: true,
		easing: 'easeInOutCubic',
		speed: 800
	});
	

	$("#check12Carousel .carousel").jCarouselLite({
		btnNext: "#check12Carousel .next",
		btnPrev: "#check12Carousel .prev",
		visible: 1,
		easing: 'easeInOutCubic',
		circular: true,
		speed: 900,
		auto: 8000,
		afterEnd: function(a) {
			$("#check12Carousel li").hover(
			  function () {
				 $(".infoOverlay",this).fadeIn("fast");
			  }, 
			  function () {
				 $(".infoOverlay",this).fadeOut("fast");
			  }
			);
		}

	});
	

	/////////////////////////// TABS	
	
	$('#resources > ul').tabs({ fx: { opacity: 'toggle'} });
	//$('#resources > ul').tabs();
	
	/*var $tabs = $('#resources > ul').tabs(); // first tab selected

	//$('#resources > ul').tabs();

	$('#tabJobs').click(function() { // bind click event to link
	    $tabs.tabs('select', 0); // switch to third tab
	    return false;
	});
	$('#tabLearn').click(function() { // bind click event to link
	    $tabs.tabs('select', 1); // switch to third tab
	    return false;
	});
	$('#tabLove').click(function() { // bind click event to link
	    $tabs.tabs('select', 2); // switch to third tab
	    return false;
	});*/
		
	
	/////////////////////////// SMOOTHE IMAGE LOADING 
	// http://www.bennadel.com/blog/1007-jQuery-Attr-Function-Doesn-t-Work-With-IMAGE-complete.htm
	/*
	$("img").animate({ 
		opacity: 0
	}, 0 );
	
	$("img").load(function(evt){
		$(evt.target).animate({ 
			opacity: 1
		}, 200 );
	});

	if($("img")[0].complete){
		$("img").animate({ 
			opacity: 1
		}, 400 );
	}
	*/
	
	
	//attach directly to each image within each .imageSection 
    $('img').onImagesLoad({ 
        itemCallback: itemImagesLoaded,
        selectorCallback: selectorImagesLoaded
    }); 
    //itemImagesLoaded (the itemCallback) is invoked once for each individual image that loads 
    //i.e. the itemCallback will be invoked "$('.imageSection img').length" times 
    function itemImagesLoaded(domObject){ 
        $(domObject).animate({ 
			"opacity": "1"
		}, 400 );
    } 
	//selectorImagesLoaded (the selectorCallback) is invoked only once: when all images that 
    //$('.imageSection') encapsulates have loaded 

    
   // setTimeout("selectorImagesLoaded()",2000);


	/////////////////////////// COMMENT CODE BALLOON	
	
	$('a.zoom').fancyZoom({closeOnClick: true});

	$("#comment").focus(function () {
		$("#commentCode").fadeIn("100");
		});
	$("#comment").blur(function () {
		$("#commentCode").fadeOut("100");
		});

	/////////////////////////// CURVYCORNERS

	$(function(){ 
  
  	settings = {
          tl: { radius: 5 },
          tr: { radius: 5 },
          bl: { radius: 5 },
          br: { radius: 5 },
          antiAlias: true,
          autoPad: true,
          validTags: ["div"]
      }

	  $('.textBox').corner(settings);
	  
	  });;


	
});

