$(document).ready(function(){

// ZOOM

$(".mainImg").jqzoom({
	zoomWidth: 300,
	zoomHeight: 300,
	position : 'right',
	yOffset :0,
	xOffset :20,
	showEffect:'show',
	hideEffect:'fadeout',
	fadeoutSpeed: 'fast',
	title :false

});

// 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/homebag_henley-plain.jpg)");

// VALIDATE
	$("#newsletterForm").validate();
	$("#airegisterForm").validate();
	$("#silvercontactForm").validate();
	$("#silvercallbackForm").validate();
	$("#businesscontactForm").validate();
	$("#mharegisterForm").validate();
	$("#newsletterForm").validate();

//check for nav item with children
	$(".lnav li:has(ul)").addClass("daddy");
		
// THUMB HOVER
	$("#alternateImages 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
		});
		
// 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(3)").addClass("active");
		}
		else if(path.search('silver/') > -1){
			$(".tnav a:eq(2)").addClass("active");
		}
		else if(path.search('contact_us/') > -1){
			$(".tnav a:eq(4)").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");
		
// REFLECT
		
		if (document.location.href.indexOf("/press/") > -1) {
			$('img.reflect').reflect();
		}
		else if (document.location.href.indexOf("/press-archive-2009/") > -1) {
			$('img.reflect').reflect();
		}
		else if (document.location.href.indexOf("/press-archive-2008/") > -1) {
			$('img.reflect').reflect();
		}
		else if (document.location.href.indexOf("/press-archive-2007/") > -1) {
			$('img.reflect').reflect();
		}
		else if (document.location.href.indexOf("/trophy-gallery/") > -1) {
			$('img.reflect').reflect();
		}
		else if (document.location.href.indexOf("/trophy-gallery-2/") > -1) {
			$('img.reflect').reflect();
		}
		else if (document.location.href.indexOf("/trophy-gallery-3/") > -1) {
			$('img.reflect').reflect();
		}
		else if (document.location.href.indexOf("/trophy-gallery-4/") > -1) {
			$('img.reflect').reflect();
		}
		else if (document.location.href.indexOf("/trophy-gallery-all/") > -1) {
			$('img.reflect').reflect();
		}
		else if (document.location.href.indexOf("/trophy-gallery-all/") > -1) {
			$('img.reflect').reflect();
		}
		else if (document.location.href.indexOf("/medal-design-creation/") > -1) {
			$('img.reflect').reflect();
		}
		else if (document.location.href.indexOf("/silversmith-and-bespoke/") > -1) {
			$('img.reflect').reflect();
		}

});
// 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;
		});
	};
	
// ADD SWF FILES
	var flashvars = null;
	var params = { bgcolor: "#000000" };
	var attributes = null;
	swfobject.embedSWF("/media/silver.swf", "silverswf", "175", "315", "8.0.0", "/media/expressInstall.swf", flashvars, params, attributes);
