(function($j){$j.InFieldLabels=function(b,c,d){var f=this;f.$jlabel=$j(b);f.label=b;f.$jfield=$j(c);f.field=c;f.$jlabel.data("InFieldLabels",f);f.showing=true;f.init=function(){f.options=$j.extend({},$j.InFieldLabels.defaultOptions,d);if(f.$jfield.val()!=""){f.$jlabel.hide();f.showing=false};f.$jfield.focus(function(){f.fadeOnFocus()}).blur(function(){f.checkForEmpty(true)}).bind('keydown.infieldlabel',function(e){f.hideOnChange(e)}).change(function(e){f.checkForEmpty()}).bind('onPropertyChange',function(){f.checkForEmpty()})};f.fadeOnFocus=function(){if(f.showing){f.setOpacity(f.options.fadeOpacity)}};f.setOpacity=function(a){f.$jlabel.stop().animate({opacity:a},f.options.fadeDuration);f.showing=(a>0.0)};f.checkForEmpty=function(a){if(f.$jfield.val()==""){f.prepForShow();f.setOpacity(a?1.0:f.options.fadeOpacity)}else{f.setOpacity(0.0)}};f.prepForShow=function(e){if(!f.showing){f.$jlabel.css({opacity:0.0}).show();f.$jfield.bind('keydown.infieldlabel',function(e){f.hideOnChange(e)})}};f.hideOnChange=function(e){if((e.keyCode==16)||(e.keyCode==9))return;if(f.showing){f.$jlabel.hide();f.showing=false};f.$jfield.unbind('keydown.infieldlabel')};f.init()};$j.InFieldLabels.defaultOptions={fadeOpacity:0.5,fadeDuration:300};$j.fn.inFieldLabels=function(c){return this.each(function(){var a=$j(this).attr('for');if(!a)return;var b=$j("input#"+a+"[type='text'],"+"input#"+a+"[type='password']");if(b.length==0)return;(new $j.InFieldLabels(this,b[0],c))})}})(jQuery);

$j(function(){$j(".form-search label").inFieldLabels(); });
$j(function(){$j(".newsletter label").inFieldLabels(); });

//Font Replacement
Cufon.replace('.category-title h1,.footer h4, .product-view .product-shop .product-name h1,.page-title h1, .page-title h2,.wired-home .subscribe strong', {
	hover: true
});

jQuery(document).ready(function() {
	
	var navContainer=jQuery("#navigation .nav-container").css('width');
	var access=jQuery("#navigation .access").css('width');
	if(navContainer == 'auto' || access == 'auto'){
		navContainer=jQuery("#navigation .nav-container").width();
		access=jQuery("#navigation .access").width();
	}
	var searchFormLeft = parseInt(access) + parseInt(navContainer);
	jQuery("#search_mini_form").css("margin-left",searchFormLeft);
	
	// For add class on Main Category nav menu
	
	jQuery(".cms-links ul>li:last").addClass("last");	
	if(!jQuery(".cms-links ul>li").hasClass("active")){	
	jQuery(".cms-links ul>li a span").each(function(){ 
		
		Women_check=jQuery(this).text();
		//if(!jQuery(this).parent().parent().hasClass("active")){
			if(Women_check=="Women"){
				
				jQuery(this).parent().parent().addClass("active");
					
			}
		//}
		});
	}	
	// Featured Products
    jQuery('#featured').jcarousel();
	// FancyBox jQuery
	jQuery("a.group").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': true }); 	
	// Slider Homepage
	jQuery('#slider').cycle({
        fx: 'fade',
        speed: 2000,
		timeout: 5000,
        pager: '#controls',
		slideExpr: '.panel'
    });
});

/*
product image mouse over/mouse out show/hiding the second image
*/
jQuery(document).ready(function() { 
  jQuery("ul.products-grid li.item a").hover(
  function() {
  	var secound_image_src = jQuery(this).find("img.second-image").attr('src');
	var pathArray = secound_image_src.split('/');
	var len = pathArray.length;
  	if((jQuery(this).find("img.second-image").attr('src') != jQuery(this).find("img.first-image").attr('src')) && pathArray[len-1] != "thumbnail.jpg")
	{
		jQuery(this).find("img.first-image").stop(true,true).fadeOut(1);
		jQuery(this).find("img.second-image").stop(true,true).fadeIn(1);
	}
  },
  function() {
  	jQuery(this).find("img.first-image").stop(true,true).fadeIn(1);
	jQuery(this).find("img.second-image").stop(true,true).fadeOut(1);
  });
  
});

function productPopupVideo (productId) {
	var j1 = document.getElementById("hiddenclicker");
	j1.href = '/videoPopup.php?productId='+productId;
	
	jQuery("#hiddenclicker").fancybox({
		'autoScale'    	  : false,
		'transitionIn'    : 'none',
		'transitionOut'   : 'none',
		'hideOnContentClick' : false,
		'titleShow'		  : false,
		'padding'		  : 0,
		'frameWidth'	  :	700,
		'frameHeight'	  :	650,
		'width'  		  : 700,
        'height' 		  : 650,
		'type'            : 'iframe'
   }); 
	
	jQuery('#hiddenclicker').trigger('click');
}

function productPopupShare (productId,productName) {
	var j1 = document.getElementById("hiddenclicker");
	j1.href = '/sharePopup.php?productId='+productId+'&text='+productName;
	
     jQuery("#hiddenclicker").fancybox({
		'autoScale'    	  : false,
		'transitionIn'    : 'none',
		'transitionOut'   : 'none',
		'hideOnContentClick' : false,
		'titleShow'		  : false,
		'padding'		  : 0, 
		'margin'          : 0,
		'left'            : 0,
		'right'           : 0, 
		'frameWidth'	  :	505,
		'frameHeight'	  :	270,
		'width'           : 505,
		'height'          : 270,
		'type'            : 'iframe'
   });
	
	jQuery('#hiddenclicker').trigger('click');
}

function productPopupPrint (productId) { 
	var j1 = document.getElementById("hiddenclicker");
	j1.href = '/printPopup.php?productId='+productId;
	
	jQuery('#hiddenclicker').fancybox({
		'autoScale'    	  : false,
		'transitionIn'    : 'none',
		'transitionOut'   : 'none',
		'hideOnContentClick' : false,
		'titleShow'		  : false,
		'padding'		  : 0, 
		'margin'          : 0,
		'left'            : 0,
		'right'           : 0,
		'frameWidth'	  :	700,
		'frameHeight'	  :	480,
		'width'           : 700,
		'height'          : 480,
		'type'            : 'iframe'			
   });
	
	jQuery('#hiddenclicker').trigger('click');
}

/* for Tab menu in Product Info Page */

function ddtabcontent(tabinterfaceid){
	this.tabinterfaceid=tabinterfaceid //ID of Tab Menu main container
	this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a") //Get all tab links within container
	this.enabletabpersistence=true
	this.hottabspositions=[] //Array to store position of tabs that have a "rel" attr defined, relative to all tab links, within container
	this.currentTabIndex=0 //Index of currently selected hot tab (tab with sub content) within hottabspositions[] array
	this.subcontentids=[] //Array to store ids of the sub contents ("rel" attr values)
	this.revcontentids=[] //Array to store ids of arbitrary contents to expand/contact as well ("rev" attr values)
	this.selectedClassTarget="link" //keyword to indicate which target element to assign "selected" CSS class ("linkparent" or "link")
}

ddtabcontent.getCookie=function(Name){ 
	var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
		return document.cookie.match(re)[0].split("=")[1] //return its value
	return ""
}

ddtabcontent.setCookie=function(name, value){
	document.cookie = name+"="+value+";path=/" //cookie value is domain wide (path=/)
}

ddtabcontent.prototype={

	expandit:function(tabid_or_position){ //PUBLIC function to select a tab either by its ID or position(int) within its peers
		this.cancelautorun() //stop auto cycling of tabs (if running)
		var tabref=""
		try{
			if (typeof tabid_or_position=="string" && document.getElementById(tabid_or_position).getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=document.getElementById(tabid_or_position)
			else if (parseInt(tabid_or_position)!=NaN && this.tabs[tabid_or_position].getAttribute("rel")) //if specified tab contains "rel" attr
				tabref=this.tabs[tabid_or_position]
		}
		catch(err){alert("Invalid Tab ID or position entered!")}
		if (tabref!="") //if a valid tab is found based on function parameter
			this.expandtab(tabref) //expand this tab
	},

	cycleit:function(dir, autorun){ //PUBLIC function to move foward or backwards through each hot tab (tabinstance.cycleit('foward/back') )
		if (dir=="next"){
			var currentTabIndex=(this.currentTabIndex<this.hottabspositions.length-1)? this.currentTabIndex+1 : 0
		}
		else if (dir=="prev"){
			var currentTabIndex=(this.currentTabIndex>0)? this.currentTabIndex-1 : this.hottabspositions.length-1
		}
		if (typeof autorun=="undefined") //if cycleit() is being called by user, versus autorun() function
			this.cancelautorun() //stop auto cycling of tabs (if running)
		this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]])
	},

	setpersist:function(bool){ //PUBLIC function to toggle persistence feature
			this.enabletabpersistence=bool
	},

	setselectedClassTarget:function(objstr){ //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link")
		this.selectedClassTarget=objstr || "link"
	},

	getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to
		return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref
	},

	urlparamselect:function(tabinterfaceid){
		var result=window.location.search.match(new RegExp(tabinterfaceid+"=(\\d+)", "i")) //check for "?tabinterfaceid=2" in URL
		return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
	},

	expandtab:function(tabref){
		var subcontentid=tabref.getAttribute("rel") //Get id of subcontent to expand
		//Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easily search through
		var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/\s+/, "")+"," : ""
		this.expandsubcontent(subcontentid)
		this.expandrevcontent(associatedrevids)
		for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected"
			this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("rel")==subcontentid)? "selected" : ""
		}
		if (this.enabletabpersistence) //if persistence enabled, save selected tab position(int) relative to its peers
			ddtabcontent.setCookie(this.tabinterfaceid, tabref.tabposition)
		this.setcurrenttabindex(tabref.tabposition) //remember position of selected tab within hottabspositions[] array
	},

	expandsubcontent:function(subcontentid){
		for (var i=0; i<this.subcontentids.length; i++){
			var subcontent=document.getElementById(this.subcontentids[i]) //cache current subcontent obj (in for loop)
			subcontent.style.display=(subcontent.id==subcontentid)? "block" : "none" //"show" or hide sub content based on matching id attr value
		}
	},

	expandrevcontent:function(associatedrevids){
		var allrevids=this.revcontentids
		for (var i=0; i<allrevids.length; i++){ //Loop through rev attributes for all tabs in this tab interface
			//if any values stored within associatedrevids matches one within allrevids, expand that DIV, otherwise, contract it
			document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none"
		}
	},

	setcurrenttabindex:function(tabposition){ //store current position of tab (within hottabspositions[] array)
		for (var i=0; i<this.hottabspositions.length; i++){
			if (tabposition==this.hottabspositions[i]){
				this.currentTabIndex=i
				break
			}
		}
	},

	autorun:function(){ //function to auto cycle through and select tabs based on a set interval
		this.cycleit('next', true)
	},

	cancelautorun:function(){
		if (typeof this.autoruntimer!="undefined")
			clearInterval(this.autoruntimer)
	},

	init:function(automodeperiod){
		var persistedtab=ddtabcontent.getCookie(this.tabinterfaceid) //get position of persisted tab (applicable if persistence is enabled)
		var selectedtab=-1 //Currently selected tab index (-1 meaning none)
		var selectedtabfromurl=this.urlparamselect(this.tabinterfaceid) //returns null or index from: tabcontent.htm?tabinterfaceid=index
		this.automodeperiod=automodeperiod || 0
		for (var i=0; i<this.tabs.length; i++){
			this.tabs[i].tabposition=i //remember position of tab relative to its peers
			if (this.tabs[i].getAttribute("rel")){
				var tabinstance=this
				this.hottabspositions[this.hottabspositions.length]=i //store position of "hot" tab ("rel" attr defined) relative to its peers
				this.subcontentids[this.subcontentids.length]=this.tabs[i].getAttribute("rel") //store id of sub content ("rel" attr value)
				this.tabs[i].onclick=function(){
					tabinstance.expandtab(this)
					tabinstance.cancelautorun() //stop auto cycling of tabs (if running)
					return false
				}
				if (this.tabs[i].getAttribute("rev")){ //if "rev" attr defined, store each value within "rev" as an array element
					this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/\s*,\s*/))
				}
				if (selectedtabfromurl==i || this.enabletabpersistence && selectedtab==-1 && parseInt(persistedtab)==i || !this.enabletabpersistence && selectedtab==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){
					selectedtab=i //Selected tab index, if found
				}
			}
		} //END for loop
		if (selectedtab!=-1) //if a valid default selected tab index is found
			this.expandtab(this.tabs[selectedtab]) //expand selected tab (either from URL parameter, persistent feature, or class="selected" class)
		else //if no valid default selected index found
			this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr
		if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){
			this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)
		}
	} //END int() function

} //END Prototype assignment

//Script for thumbnail arrow functionality in product detail page starts here.

var selectedImage = 1;
var lastSelectedImage = 1;
var interval;
var play = true;
var galleryTimeDelay = 10000;	// 1 sec = 1000ms; 10sec = 10000
var isPlayPause = false;

function startGallery()
{
	val = document.getElementById('imgcnt').value;
	interval = setInterval("NextImg("+val+")", galleryTimeDelay);
}

function stopGallery()
{ 
	if(play)
	{
		clearInterval(interval);
		play = false;
		document.getElementById('pause').title = "Play";
		document.getElementById('pause').className = 'btn-play';
	}
	else
	{ 
		play = true;
		document.getElementById('pause').title = "Pause";
		document.getElementById('pause').className = 'btn-pause';
		startGallery();
	}
}

function NextImg(imgcnt) { 
	selectedImage++;
	if(selectedImage > imgcnt)
	{
		selectedImage = 1;
	}
	selectedImage = selectedImage;
	nextimg = document.getElementById('thumbname'+selectedImage).value;  
	switchTo('event','/media/catalog/product/deepzoom'+nextimg+'.dzi',selectedImage);
}

function PrevImg(imgcnt) {
	selectedImage--;
	if(selectedImage == 0)
	{
		selectedImage = parseInt(imgcnt); 
	}
	nextimg = document.getElementById('thumbname'+selectedImage).value; 
	switchTo('event','/media/catalog/product/deepzoom'+nextimg+'.dzi',selectedImage);
}

function setTarget()
{
	document.getElementById('item'+selectedImage).className = 'selected';
	if(selectedImage != lastSelectedImage)
		document.getElementById('item'+lastSelectedImage).className = '';
	lastSelectedImage = selectedImage;
}
//End.

//pagination Script Info Designer Page Start//
var currentPageId = "#designer_products_1";
var currentPage = 1;
var total_page = 1;

function showDesignerProducts(pageNr)
{
	if(pageNr == total_page){jQuery("#designer_next").hide();}	
	if(pageNr < total_page){jQuery("#designer_next").show();}
	if(pageNr > 1){jQuery("#designer_previous").show();}
	if(pageNr == 1) {jQuery("#designer_previous").hide();}
	
	var showPageId = "#designer_products_" + pageNr;
	
	jQuery(currentPageId).hide();
	jQuery(showPageId).show();
	
	currentPageId = showPageId;
	currentPage = pageNr;

	for(i=1;i<=total_page;i++)
	{
	   if(i!=pageNr)
	   {
		  jQuery('#pageno_'+i).removeClass('current');
	   }
	   else
	   {
		  jQuery('#pageno_'+i).addClass('current');
	   }
	}
}

jQuery(document).ready(function() {	
	if(total_page == '1'){jQuery("#designer_next").hide();}	
	if(total_page == '0'){jQuery("#designer_next").hide();}
	jQuery("#designer_next").click(function(){
    	currentPage++;
		showDesignerProducts(currentPage);
    });
	jQuery("#designer_previous").click(function(){
    	currentPage--;
		showDesignerProducts(currentPage);
    });
});
//pagination Script Info Designer Page End//

//pagination Script Related products Page Start//
var currentPageIds = "#related_products_1";
var currentPages = 1;
var total_pages = 1;

function showRelatedProducts(pageNr)
{
	if(pageNr == total_pages ){jQuery("#top_related_next").hide();jQuery("#bot_related_next").hide();}	
	if(pageNr < total_pages){jQuery("#top_related_next").show();jQuery("#bot_related_next").show();}
	if(pageNr > 1){jQuery("#top_related_previous").show();jQuery("#bot_related_previous").show();}
	if(pageNr == 1) {jQuery("#top_related_previous").hide();jQuery("#bot_related_previous").hide();}
	
	var showPageId = "#related_products_" + pageNr;
	
	jQuery(currentPageIds).hide();
	jQuery(showPageId).show();
	
	currentPageIds = showPageId;
	currentPages = pageNr;

	for(i=1;i<=total_pages;i++)
	{
	   if(i!=pageNr)
	   {
		  jQuery('#toppagenos_'+i).removeClass('current');
		  jQuery('#botpagenos_'+i).removeClass('current');
	   }
	   else
	   {
		  jQuery('#toppagenos_'+i).addClass('current');
		  jQuery('#botpagenos_'+i).addClass('current');
	   }
	}
}

jQuery(document).ready(function() {
	
	if(total_pages == '1'|| total_pages == '0' ){jQuery("#top_related_next").hide(); jQuery("#bot_related_next").hide();}
	
	jQuery("#top_related_next").click(function(){
    	currentPages++;
		showRelatedProducts(currentPages);
    });
	jQuery("#bot_related_next").click(function(){
    	currentPages++;
		showRelatedProducts(currentPages);
    });
	jQuery("#top_related_previous").click(function(){
    	currentPages--;
		showRelatedProducts(currentPages);
    });
	jQuery("#bot_related_previous").click(function(){
    	currentPages--;
		showRelatedProducts(currentPages);
    });
});
//pagination Script Related products Page End//


