$(document).ready(function() {
    InitSite();

});

//GENERIC SITE----------------------------------------------------------------------------->

function InitSite(){
	
	//Handles external links for STRICT Doctype
	$('a[href^="http://"], a[href^="https://"]').attr({
		target: "_blank"
	});
	$('#tb-model-search').focus(function(){
	
		$(this).attr('value','');
	});
}

function InitHome(){
	/*$(".home-slides").jCarouselLite({
		visible: 1,
		auto: 4000,
    	easing: "easeinout",
		speed: 1000,
		btnGo:
		[".home-pagination .one", ".home-pagination .two",
		".home-pagination .three", ".home-pagination .four",
		".home-pagination .five"]
	});*/
	
	//$("#home-product-images IMG").reflect();
	$(".home-products").jCarouselLite({
		btnNext: ".home-next",
		btnPrev: ".home-prev",
		visible:	6,
		easing: "easeinout",
		speed: 700
	});
}

function InitProductList(){
	$(".product-intro").each(function(){
			$(this).css("height", $(this).height()+"px");
			$(this).hide();
	}); 
	
	$("a.more-info").each(
        function() {
            $( this ).bind (
                "click",
                function(evt){
					evt.preventDefault();
					var currentText = "#" + $(this).attr("rel");
                    $(currentText).slideToggle();
					if($(this).text() == "[+] more info"){
						$(this).text("[-] more info");
					}else{
						$(this).text("[+] more info");
					}
                }
            );
        }
        
    );
	
	//product sub nav
	$('#product-subnav LI A').click(function(evt) {
			//alert($(this).attr("rel"));
			var pagePos = $(this).attr("href").toString();
			evt.preventDefault();
			if($.browser.opera){$('html').animate({scrollTop: $(pagePos).offset().top}, 1000);} else $('html,body').animate({scrollTop: $(pagePos).offset().top}, 1000);
	});
	
	var count = 0;
	//$("#frmProducts").clearForm();

	//handle compare checkboxes
    $("input").click(
        function( objEvent ){
			//objEvent.preventDefault();
            if(this.checked == true ){
                //check that there are not already 6 items selected
                if(count != 3){
                    count = count + 1;
                    $(this).parent().find('LABEL').css('display', 'none');
                    $(this).parent().find('a.compare').css('display', 'block');
                }else{
					$.prompt('You cannot compare more than 3 items');                 
                    this.checked = false;
                }
            }else{
                count = count - 1;
                $(this).parent().find('LABEL').css('display', 'block');
                $(this).parent().find('a.compare').css('display', 'none');
            }
  
        }
    );

    $( "a.compare" ).click(
        function( objEvent ){
			objEvent.preventDefault();
            if(count < 2){
               $.prompt('Please select at least 2 products to compare');
            }else{
               $('#frmProducts').submit();
            }
  
        }
    );
}

/*function ReplaceFonts(){
	Cufon.replace('h1, h2', { fontFamily: 'GothamBook', hover: true});
	Cufon.replace('#sub-nav, .file-types LI', { fontFamily: 'GothamMedium', hover: true});
	Cufon.replace('h1 span, h2 span', { fontFamily: 'GothamBlack', hover: true });
}*/

function InitProductDetail(){
	InitTabs();
	
	curTitle = $("H1").html();
	$(".facebook").attr("href", "http://www.facebook.com/sharer.php?u=" + window.location + "&t=" + curTitle);
	$(".tweet").attr("href", "http://twitter.com/home?status=" + window.location);
	
	$('#btnPrintall').click(function() {
		window.open('print.cfm?productuid='+$("#productuid").val()+'&'+'all=all',"mywindow",
    "location=0,status=1,scrollbars=1,width=700,height=900,toolbar=0");
		return false;
	});
	$("#chkSelectallfeature").click(function() {
		$("input[name='chkFeaturesection']").attr('checked', this.checked);		
	});
	$("#chkSelectallspec").click(function() {
		$("input[name='chkSpecsection']").attr('checked', this.checked);		
	});
	$('#btnPrintSelect').click(function() {
		var s_features=''; var s_specs='';
		$("input[name='chkFeaturesection']:checked").each(
			  function() {
				 
				  s_features= this.value + ';' + s_features ; 
			  
			  }
		);	
		$("input[name='chkSpecsection']:checked").each(
			  function() {
				  s_specs= this.value + ';' + s_specs  ; 
			  
			  }
		);	
		
		if (s_features.length ==0 && s_specs.length == 0){
		 $.prompt('Please select some product information section to print.');
		}else
		window.open('print.cfm?productuid='+$("#productuid").val()+'&'+'specs='+s_specs+'&features='+s_features,"mywindow",
    "location=0,status=1,scrollbars=1,width=700,height=900,toolbar=0");
		return false;
	});
	$("a.email").click(function () {
		$.prompt(txt,{
				 submit: mysubmitfunc,
				 buttons: { Send:true }
				}); 
	});
	$("a.external").click(function (event) {
									
		$(this).unbind('mouseout');//$(this).unbind('click');
		var i=$("a[rel='tooltip']").index(this);
		var e=$("div.tooltip").eq(i);
		 
		//alert('g');
		  $(e).center();
		  $(e).append('<a id="fancybox-close">&nbsp;</a>');
		//$(e).animate({  "left": "100","top": "50", "opacity": 1 }, 500);
		//$('html,body').animate({scrollTop: 0}, 500);
		 $(e).click(function () {  $(this).slideUp();  });
	});
	
	
	// TOOLTIP BUG FIX - CORY
	var currentTip = null;
	$('.ttlink').mouseenter(function(evt) {
			currentTip = "#" + $(this).attr("rel");
			evt.preventDefault();
			$(currentTip).fadeIn("fast");
	});
	$('.ttlink').mouseleave(function(evt) {
			currentTip = "#" + $(this).attr("rel");
			evt.preventDefault();
			$(currentTip).fadeOut("fast");
	});

}
function InitTabs(){
	var curItem = null;
	
	//hide all divs apart from first
	$(".tab-section").each(
        function(intIndex ) {
			if(intIndex == 0){
				curItem = "#" + $(this).attr("id");
				$(curItem).css("display", "block");
			}
        }
    ); 
	
	
	$(".tabs li A").each(
        function() {
            $( this ).bind (
                "click",
                function(evt){
					evt.preventDefault();
					if($(this).attr("href") != curItem){
						$(".tabs li a").removeClass("selected");
						//make selected element
						$(this).addClass("selected");
						//hide current
						$(curItem).css("display", "none");
						curItem = $(this).attr("href");	
						//show new
						$(curItem).css("display", "block");
					}
                }
            );
        }
    ); 
}

