$(document).ready(function(){
	if (typeof(SHOW_KS_INFO_BOX) != "undefined" && SHOW_KS_INFO_BOX == 1) {
		$.fn.colorbox({href:"ks_info.html", open:true, title: "KS Piercing"});
	}
	$("#main-nav li a.main-link").mouseenter(function(){
		$("#main-nav li a.close").fadeIn();
		$("#main-nav li a.main-link").removeClass("active");												 
		$(this).addClass("active");										 
		
		$(".sub-links").hide();
		$(this).siblings(".sub-links").fadeIn();
	});
	$("#main-nav li a.close").click(function(){
		$("#main-nav li a.main-link").removeClass("active");												 									 
		$(".sub-links").fadeOut();
		$("#sub-link-bar").animate({
			height: "10px"					   
		});		
		$("#main-nav li a.close").fadeOut();
	});
	
	//$(".cBoxProductInfo").colorbox({width:"625px"}); // loads colorbox for product info
	$(".enlargedMap").colorbox({width:"820px"}); // map colorbox
	
	$("a.asyncLoad").click(function(event){
		$('#contentColumnWrapper').css('height', '690px');
		shadowOn();
		asyncLoadContent($(this), event)
	});
	
	// product_info colorbox
	loadcBoxProductInfo();
	
	// initializes jCarousel
	initjCarousel();
	
	// applies shadow on div
	shadowOn();
	
	// initalises simple jquery menu
	$('.tree_menu').initMenu();
});

$(document).bind("contextmenu",function(e){
	alert ('2011 All Copyright © reserved by KISSISKS');
    return false;
});

// Function to load ajax pages
function asyncLoadContent(_obj, _event) {
	_event.preventDefault();
	$("a.asyncLoad").removeClass('selected');
	$(_obj).addClass('selected');
	var loadURL = $(_obj).attr('href');
	
	$.ajax({
		url: loadURL,
		beforeSend: function() {
			$('#contentColumn').html('');
			$('#contentColumn').addClass('loading');
		},
		success: function(data) {
			$('#contentColumn').removeClass('loading');
			$('#navBreadCrumb').html('').hide();
			$('#contentColumn').html(data);
			
			// product_info colorbox
			loadcBoxProductInfo();
		 	
		 	// ks poster images' group
		 	$("a[rel='grpKSPoster']").colorbox();
		 	
		 	// map colorbox
		 	$(".enlargedMap, .enlargedImg").colorbox({width:"820px"});
		 	
		 	// load inner ajax contentColumn
		 	$("a.asyncLoadInner").click(function(event){
		 		$('#contentColumnWrapper').css('height', '690px');
		 		shadowOn();
				asyncLoadContent($(this), event)
			});
			
			// anything slider
			$('#slider1').anythingSlider({
				startStopped    : false, // If autoPlay is on, this can force it to start stopped
				width           : 660,   // Override the default CSS width
				height          : 330,   // Override the default CSS width
				theme           : 'metallic',
				autoPlayLocked  : true,  // If true, user changing slides will not stop the slideshow
				resumeDelay     : 20000 // Resume slideshow after user interaction, only if autoplayLocked is true (in milliseconds).
			});
			
			// init jcarousel
			initjCarousel();
			
			$('#contentColumnWrapper').css('height', 'auto');
			// applies shadow
			shadowOn();
		}
	});
}

// Function to load colorbox for product info
function loadcBoxProductInfo() {
	$(".cBoxProductInfo").colorbox({
 		width:"625px",
 		onComplete:function(){
 			var options = { 
			    target:     '#product_cart_container', 
			    success:    function(responseText, statusText, xhr, $form) { 
			        //$('#header_cart_info').html(responseText);
			        $.ajax({
						url: 'update_cart_async.php',
						success: function(data) { $('#header_cart_info').html(data);}
					});
			        $.fn.colorbox.close();
			    } 
			}; 
			
			$(".cBoxProductInfoMove").colorbox({width:"625px"});
			
			// pass options to ajaxForm 
			$('#addProductToCartForm').ajaxForm(options);
 		}
 	});
}

// Function initialzes jCarouselLite
function initjCarousel() {
	$("#jCarouselGallery").jCarouselLite({
		btnNext: ".lNext",
        btnPrev: ".lPrev",
    	auto: 800,
    	speed: 2000,
	});
}

// Function to bookmark the site
function bookmark_us(url, title)
{
	if (window.sidebar){ // firefox
	    window.sidebar.addPanel(title, url, "");
	}
	else if(window.opera && window.print){ // opera
	    var elem = document.createElement('a');
	    elem.setAttribute('href',url);
	    elem.setAttribute('title',title);
	    elem.setAttribute('rel','sidebar');
	    elem.click();
	}
	else if(document.all){// ie
	    window.external.AddFavorite(url, title);
	}
}

// Function to apply shadow effect on div
function shadowOn() {
	return;
	/*
	// shadow effect
	$('#contentColumnWrapper').shadowOn({
    	imagepath: TEMPLATE_PATH + 'images',
    	imageset: 3
    });
    */
}
