$(document).ready(function(){
	
	
	// Product Sub-Nav Dropdizzle
	
	var ladder = new Ladder();
	var config = {    
         sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
         interval: 100,  // number = milliseconds for onMouseOver polling interval    
         over: doOpen,   // function = onMouseOver callback (REQUIRED)    
         timeout: 200,   // number = milliseconds delay before onMouseOut    
         out: doClose    // function = onMouseOut callback (REQUIRED)    
    };
    
    function doOpen() {
        $(this).addClass("hover");
        $('ul:first',this).slideDown(450, 'easeOutExpo');
    }
 
    function doClose() {
        $(this).removeClass("hover");
        $('ul:first',this).slideUp(450, 'easeOutExpo');
    }

    $("li.dropdown").hoverIntent(config);
	
	//Show Hide Q&A
	var firstRun = true;
	var initDelay = 0;
	var customDelay = 100;
	
	$('.answer').hide();
	$('.question').click(initHide)
	
	
	
	function initHide(){
	
	  var current_delay; 
	
	  if(firstRun == true){
	      current_delay = initDelay;
	      firstRun = false;
	  }else{
	      current_delay = customDelay;
	  }
	
	
	  $('.answer').slideUp(500, 'easeOutExpo');
	
	  if( $(this).next().is(':hidden')){
	      $(this).toggleClass('active').next().delay(current_delay).slideToggle(500, 'easeOutExpo')
	  }else{
	      firstRun = true;
	  }

	}
	
	// Photos Page
	
    $("#photos-wrap .image").hover(function(){
        $(this).find('img').stop().fadeTo(200, 0.7);
    },
    function(){
        $(this).find('img').stop().fadeTo(200, 1);
    });
    
	// ! SLIDESHOW NAVIGATION STUFF!!!
	var count;
	
	if($('#profile-slider img').length > 0){
		count = $('#profile-slider img').length;
	}else if($('#product-slider img').length > 0){
		count = $('#product-slider img').length;
		
	}
	
	var slideshowNav = $('a#product-prev, a#product-next, a#profile-prev, a#profile-next');
	
	slideshowNav.fadeTo(200, 0.5);
	
	slideshowNav.hover(
		
		function(){
			$(this).stop().fadeTo(200, 1)
			},
		function(){
			$(this).stop().fadeTo(200, 0.5)
			}
		);	
	
	//Hide if not needed
	if (count < 2){
		slideshowNav.fadeTo(300,0).hide();
	}
	
	// ! jQuery Cycle Slideshows
	if($('#profile-slider img').length > 0){
		
		$('#profile-slider').cycle({ 
	    	fx:     'scrollHorz', 
	    	easing:	'easeOutExpo',
	    	prev:   '#profile-prev', 
	    	next:   '#profile-next', 
	    	timeout: 0 
		});
		
	}
	
	//if($('#product-slider img').length > 0){
	
		$('#product-slider').cycle({ 
	    	fx:     'scrollHorz', 
	    	easing:	'easeOutExpo',
	    	prev:   '#product-prev', 
	    	next:   '#product-next', 
	   		timeout: 0, 
	    	before: function() {  
            	$('h5.title').html(this.alt); 
        	} 
		});
		
	//}
	


	// redefine Cycle's updateActivePagerLink function 
	/*
$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
    $(pager).find('li').removeClass('current-item') 
        .filter('li:eq('+currSlideIndex+')').addClass('current-item'); 
	}; 
*/
	
	/*
$(function() { 
    	$('#design-info').cycle({ 
       		fx:     'scrollVert',
        	easing:	'easeOutExpo', 
        	speed:   5000, 
        	timeout: 0, 
        	pager:  '#design-items', 
        
        	pagerAnchorBuilder: function(idx, slide) { 
        	return '#design-items li:eq(' + idx + ') a'; 
    		}
    	
	    }); 
	});
*/

	//The Detectorater
	//Detect IE Blah blah blah
	
	$(function(){
	
		 if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
		 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number

		 if (ieversion>=8)
		  console.log("it's going to be ok");

		 else if (ieversion>=7)
		  console.log("it's going to be ok");

		 else if (ieversion>=6)
		  $('body.home #alert').fadeIn(300)

		 else if (ieversion>=5)
		  $('body.home #alert').fadeIn(300)
		}

     
     $('#close-alert').click(function(){
     	$('#alert').fadeOut(300);
     	});
	});
	

});

	
