$(document).ready(function(){


// HOME RANDOM IMAGE
	//var randomImages = ['homebag0','homebag01','homebag2'];
	//var rndNum = Math.floor(Math.random() * randomImages.length);
	//$(".home .container").css("background-image","url(/media/homebag" + rndNum  + ".jpg)");
	//$(".home .container").css("background-image","url(/media/tl_home-storeopen.jpg)");

// VALIDATE
	$("#newsletterForm").validate();
	$("#airegisterForm").validate();
	$("#silvercontactForm").validate();
	$("#silvercallbackForm").validate();
	$("#businesscontactForm").validate();
	$("#mharegisterForm").validate();
	$("#newsletterForm").validate();
	$("#subForm").validate();

//check for nav item with children
	$(".lnav li:has(ul)").addClass("daddy");
		
// THUMB HOVER
	$("#alternateImages img, .homelcol img, .social img").hover(function(){
		$(this).fadeTo("fast", 0.6); // mouseover
	},function(){
		$(this).fadeTo("slow", 1.0); // mouseout
	});
	
	
// GALLERY
	$(function() {
        $('#zoom').lightBox();
        $('a.lightbox').lightBox({fixedNavigation:true});
        $('.zoomimg').lightBox();
        //$('#gallery a').lightBox({fixedNavigation:true});
	});
    
// GALLERY
		// fade all but first image
		$("#imgList img:not(:first)").fadeTo("fast", 0.5);
		// grab href and write to image holder
		$("#imgList a").each(
			function(){
				$(this).bind (
					"click",
					function(){
						var thisLink = $(this).attr("href");
						var thisCaption = $(this).attr("title");
						$("#mainImg img").attr("src",thisLink);
						$("#mainImg #caption").html(thisCaption);
						$("#imgList img").fadeTo("fast", 0.5);
						$(this).find("img").fadeTo("fast", 1);
						return false;
					}
				)
			}
		);
		
// ACCORDIAN
		$('.accordion').accordion({
			header: 'h3,h4',
			autoHeight: false,
			collapsible: true,
			active: false
		});

// CAROUSELS
		$(".prodcarousel").jcarousel({
			initCallback: mycarousel_initCallback,
			buttonNextHTML: "<div></div>",
			buttonPrevHTML: "<div></div>",
			scroll: 5
			//auto: 2,
		});
		
		$(".gallery").jcarousel({
			initCallback: mycarousel_initCallback,
			buttonNextHTML: "<div></div>",
			buttonPrevHTML: "<div></div>",
			vertical: true
		});
		
		$(".imgcarousel").jcarousel({
			initCallback: mycarousel_initCallback,
			buttonNextHTML: "<div></div>",
			buttonPrevHTML: "<div></div>",
			scroll: 5
			//auto: 2,
		});
		
		
		
// TOOLTIPS
		$('.prodcarousel a img').tooltip({
			showURL: false,
			extraClass: "prodtip",
			showBody: " - ",
			track: true
		});
		
// TABS
		$("#tabbed").tabs({
			fx: {
				opacity: "toggle"
			}
		});

// SET ACTIVE MENUS
		$("#footer li a").each(function() {
			if(this.href == window.location.href.split("#")[0]) {
				$(this).addClass("active");

			}
		});
		
		$("#mnav li a").each(function() {
			if(this.href == window.location.href.split("#")[0]) {
				$(this).addClass("active");
				$(this).parents("li:last").addClass("current");
			}
		});
		
		$(".aboutmenu li a").each(function() {
			if(this.href == window.location.href.split("#")[0]) {
				$(this).addClass("active");
				$(this).parents("li:last").addClass("current");
			}
		});
		
		$(".extra li a").each(function() {
			if(this.href == window.location.href.split("#")[0]) {
				$(this).addClass("active");
			}
		});
		
		var path = location.pathname.substring(1).toLowerCase();
		
		if(path.search('aboutus/') > -1){
			$(".tnav a:eq(1)").addClass("active");
		}
		else if(path.search('business/') > -1){
			$(".tnav a:eq(4)").addClass("active");
		}
		else if(path.search('silver/') > -1){
			$(".tnav a:eq(3)").addClass("active");
		}
		else if(path.search('press/') > -1){
			$(".tnav a:eq(5)").addClass("active");
		}
		else if(path.search('contact_us/') > -1){
			$(".tnav a:eq(6)").addClass("active");
		}
		else if(path.search('sale/') > -1){
			$(".tnav a:eq(7)").addClass("active");
		}
		else{
			$(".tnav a:first").addClass("active");
		}
		
		$("div").each(function(){
      	if ( $(".tnav a:eq(3)").hasClass("active") )
       		$(".tnav a:first").removeClass("active");
    	});
    	
    	$("div").each(function(){
      	if ( $(".tnav a:eq(1)").hasClass("active") )
       		$(".tnav a:first").removeClass("active");
    	});
    	
    	$("div").each(function(){
      	if ( $(".tnav a:eq(2)").hasClass("active") )
       		$(".tnav a:first").removeClass("active");
    	});
    
		
// SUPERFISH
		$("ul.sf-menu").superfish({
			pathClass: 'current'
		});

// ADD CLASSES
		$("li:first-child").addClass("first");
		$("td:first-child").addClass("first");
		$(".newslist #articles img").addClass("reflect");
		$(".formField").css("background-color","black");
		

	

});
// END JQUERY

// ADD CAROUSEL INIT
	function mycarousel_initCallback(carousel) {
		$('.jcarousel-control a').bind('click', function() {
			carousel.scroll($.jcarousel.intval($(this).text()));
			return false;
		});
	
		$('.jcarousel-scroll select').bind('change', function() {
			carousel.options.scroll = $.jcarousel.intval(this.options[this.selectedIndex].value);
			return false;
		});
	
		$('#carousel-next').bind('click', function() {
			carousel.next();
			return false;
		});
	
		$('#carousel-prev').bind('click', function() {
			carousel.prev();
			return false;
		});
	};
	


