/**
Cookie name                                          description
1) nameoftopmenu                                     cookie is set when you click on image of shop by brand,...
                                                     will used to display left navigation and highlight images

2) leftmenutoshow                                    it contain id of left nav that user has clicked to diplay it visible

3) leftmenuvisible                                   this contain whether menu visible onb left side is brand,category,size or sale

4) prevnextcookieno                                 this cookie contaning  all ids of thumbnails so that while on product page we can show the 
                                                     previouse and next feature
													 
													 
**/
  $(document).ready(function () {
	  
if($("#myScrollContainer").length>0)
{
plumscroll.load();
}

//change for mac os
var nVer = navigator.appVersion;
var nAgt = navigator.userAgent;
var nameOffset,verOffset;
if (navigator.appVersion.toLowerCase().indexOf("mac") > 0)
 {
 var fullVersion  = ''+parseFloat(navigator.appVersion); 
  
  if ( (verOffset=nAgt.indexOf("Firefox"))!=-1) {
   
                     fullVersion = nAgt.substring(verOffset+8);
				    // trim the fullVersion string at semicolon/space if present
                   if ((ix=fullVersion.indexOf(";"))!=-1) fullVersion=fullVersion.substring(0,ix);
                  if ((ix=fullVersion.indexOf(" "))!=-1) fullVersion=fullVersion.substring(0,ix);
   
                 if(parseInt(fullVersion)>=3)
                     $("div.testfornew").attr("style","overflow: hidden;height:56px");
                                             }
  }
	  /**
		  below are input feilds javascript */
		  $("#query1").click(function(){
		  $(this).val("");
		  });
		   $("#query2").click(function(){
		  $(this).val("");
		  });
		  $("#plumlogo").click(function(){
		  createCookie('leftmenuvisible',"brand");
		  createCookie('nameoftopmenu',"brand"); 
		  });

/*** when page load this function is called  ***/


/*****    most important image replacement      ****/

/**

cookieoftopmenu 
@value hold cookie 'nameoftopmenu' value like brand,category,whats new,sale or press has been clicked by user
@scope  public all function cam access it 

**/
var cookieoftopmenu = readCookie('nameoftopmenu');

/**

@logic  if when page loaded in browser first time no cookie is 'nameoftopmenu' is not set 
        so we load default brand left navigation hence we set variable cookieoftopmenu to brand below

**/
if(cookieoftopmenu){  }else{ cookieoftopmenu = "brand"; }

/**
topmenu
@value hold the id of element like brand,category,size or sale etc to access elemnt in jquery

idofleftmenu
@value   use to create usefull string or reference to access left navigation drop down span elemnt with id of brand,category etc..
**/
var topmenu = "#"+cookieoftopmenu;
var idofleftmenu = "span"+topmenu; 


/**
sd
@value  id of image to be highlighted

imgsrc
@value   source of image

**/
var sd = topmenu+"1" ;
var imgsrc = "http://lib.store.yahoo.net/lib/yhst-19758620870268/y"+cookieoftopmenu+".gif";




/**
statetment access element img to be higlighted then replace image source with yellow image path 
@here actually source of image get change from black to yellow higlighted
**/
$(sd).attr("src",imgsrc);

/**
here actually left navigation is made @hidden  all span with id brand,sale,size etc are made hidden
**/
$("#leftmenu").children("span").attr("style","display:none");

/**
leftmanu
@value hold the id pointer for span with id brand,category,size etc.
**/
var leftmenu = $(idofleftmenu);


/**
@logic
work like this
 check if the span with correspoding id exist or not eg.check span id with brand exist or not
 if exist then display the span in left navigation and set cookie 'leftmenuvisible' to its value
 if it does not exist then span with brand is is made visible then set cookie 'leftmenuvisible' to "brand"

**/
if(leftmenu.length>0)
 {
leftmenu.attr("style","display:block");
createCookie('leftmenuvisible',cookieoftopmenu)
  }
else
  {
$("#brand").attr("style","display:visible");
createCookie('leftmenuvisible',"brand");
  }
 



 /*** here we will display left navigation on load   ***/
/**
idsofcontainer 
@val hold cookie value leftmenutoshow it contain the value of id of element that user has clicked in 
     left navigation 
**/
 var idsofcontainer = readCookie('leftmenutoshow');

//alert("idsofcontainer is "+idsofcontainer)

/**
@logic
    if  leftmenutoshow cookie has any value, then split the value in array 
	this array elemnt are those span in left navigation need to be made visible 
**/
 if(idsofcontainer)
 {
 idofcontainer = idsofcontainer.split(",");
 if($("#"+idofcontainer[0]).length>0){ $("#"+idofcontainer[0]).attr("style","display:block")}/*alert("0 is not there")*/
 if($("#"+idofcontainer[1]).length>0){ $("#"+idofcontainer[1]).attr("style","display:block")}/*alert("1 is not there")*/;
 }

/**
@logic
When user click on image with class name "main" then cookie nameoftopmenu will be set with value of its id
**/
$("img.main").click(function(){
var mainid = (this.id).replace(/1/,'');
createCookie('nameoftopmenu',mainid); 
});




/***** pagination *****/
/****
@logic 
pagination need to be called when thumbnail page load so week check for contents-table table is present in document tree or not
***/

if($("#contents-table").length>0)
{

/**
get all row in the table of thumbnails page
**/
  var rowcount = $("#contents-table").find("tr").length;
 // alert(rowcount)
  
 /**
 loop through all row one by one
 **/ 
  $("#contents-table").find("tr").each(function(i) {
      /**
	  when page load we need to display only first two row
	  so make  row i=0,1  unchanged and 
	  row i=2,3.... to invisible
	  **/
	  if(i<=1)
           {
      //       alert(i); 
            } 
			else{ 
       $(this).attr("style","display:none"); }
  
   });
   
 /**
 count total pages craeted in pagination
 initialize necessary function
 **/  
var noofpage = parseInt(rowcount/2) + parseInt(rowcount%2);
var k;
var t=1;
var text = '';
var befortext = "<a href='#top' style='text-decoration:none;font-weight:bold;' id=";
var befortext1 = "<a href='#top' style='text-decoration:none;font-weight:bold;color:#E5B682;' id=";
var middletext = " class='pagination'>"
var endtextiflast = "</a>&nbsp;|&nbsp;"
var endtextifnotlast = "</a>&nbsp;|&nbsp;"

/**
create pagination tag  1|2|3|4|5|6| 
store it in text variable
**/

for(k=1;k<=noofpage;k++)
{
 if(k==1)
 {
	  text = text + befortext1 + t + middletext + k + endtextifnotlast;
 }
 else
 {
 text = text + befortext + t + middletext + k + endtextifnotlast;
 }
 t = t + 2;
}
/**
create View all tag at last
add in text variable
**/
text = text + "<a href='#top' id=viewall class='pagination'>View all</a>";
//alert(text)

/**
add the html text in document element id 'usefortext'
**/
if(rowcount>2)
$("#usefortext").html(text);

/**
this function capture event of onlclik generated by pagination tags 1|2|3|...
and result in response of displaying that correspoding row 
**/
$("a.pagination").click(function(){

/**
make all hyperlink of pagination like 1|2|3|....  to black color
**/
$("a.pagination").attr("style","color:black;text-decoration:none;")

/**
make clicked hyperlink of pagination like 1|2|3|.... selected one to orange color
**/
$(this).attr("style","color:#E5B682;text-decoration:none;")

/**
as every hyperlink 1|2|3|.... has corresponding id like
1 link had id 1
2 link has id 3
3 link has id 5
paged name correspond to first row  number of that page
like 1st page will contain 1,2 row
like 2nd page will contain 3,4 row
like 3rd page will contain 5,6 row

so we store
trno 
@var store value of 1st page hyperlink id like 1
 
**/
var trno = $(this).attr("id")

/**
check if clicked  hyperlink is view all tag then 
if yes the make all tr tag visible in content table
else
get id of selected page id which is tr and its next to be make visible
**/
if(trno =="viewall")
{
  $("#contents").attr("style","overflow:display")
     $("#contents-table").find("tr").attr("style","display:line");
 /*
  $("#contents-table").find("tr").each(function(i) {
     
       $(this).attr("style","display:line"); 
  
   });
   */
}
else
{
		  
  $("#contents-table").find("tr").each(function(i) {
      if(i + 1 == parseInt(trno)||i+1 == parseInt(trno) + 1)
           {
		   //alert(i)		   
		     $(this).attr("style","display:line");
           } 
	else  { 
			$(this).attr("style","display:none"); 
		   }
      });

}

/**
end of a.pagination clicked event
**/

   });

/** end of pagination condition here **/
}
/** pagination end here **/


/** generate prev and next tag **/
/**
we need to set cookie prevnextcookieno which hold the id of all thumnails product in comma saperated form
we set this cookie here
check whether content table exist or not

**/

if($("#contents-table").length>0)
{

prevnextcookie='';
prevnextcookie1='';
//alert("ia ma generating prev and next");
/**
loop thouh all hyperlink or thumnails  to collect id or url of pages
**/
$("a.forprev").each(function(i){


/**
only first 40 thumnails will be considered for cookie value
if first id is to be added in cookie then it should not have , befor it 
so this is done throgh 
check of i==0 then just assign value else add prev value and comma
**/
if(i<40)
{
var href = $(this).attr("href")
i==0 ? prevnextcookie = $(this).attr("href") : prevnextcookie = prevnextcookie + "," + href;
}
else
{
if(i<80)
{
var href = $(this).attr("href")
i==40 ? prevnextcookie1 = $(this).attr("href") : prevnextcookie1 = prevnextcookie1 + "," + href;
}

}

});
/**
finally create cookie of prev and next
**/


createCookie('prevnextcookieno',prevnextcookie);

if(prevnextcookie1.length>0)
{
createCookie('prevnextcookieno1',prevnextcookie1);
}


}

/**  this code actually add prev and next feature  **/
	var cookieofprevnext = readCookie('prevnextcookieno');
	var cookieofprevnext1 = readCookie('prevnextcookieno1');
	if(cookieofprevnext1!=null)
	{
	if(cookieofprevnext1.length>0)
	 cookieofprevnext = cookieofprevnext+","+cookieofprevnext1;
	}
	
if($("#useforprevnext").length>0&&cookieofprevnext!=null)
{
	/** 
		read the cookie value
		**/

/**
	read current url
	**/
var minestring = document.URL;

/**
	get url of page from document id
	**/
var sd = /.*\//	
var stringtomatch = minestring.replace(sd,'')

/**
search page url in cookies set
**/
/**
if match found then only generate prev and next
**/
  
/**
cookies value are comma saperated c0onvert to series of array
**/
    var arrayofid = cookieofprevnext.split(",");
	//alert(sd.length);
/**
	position of page id in url
	
	**/
	var posofid; 
	var matchfound = "false";
	//alert(arrayofid.length)
	
 	for (var i=0; i<arrayofid.length; i++)
	     {
				//alert(sd[i]);
				//alert(url);

				if(arrayofid[i]==stringtomatch)
				{
				
				matchfound="true";
				posofid = i;
				
				}
				
		}
		
		//alert(posofid );
		//alert(matchfound)
/**
if macth found then only print prev next	
	**/
	if(matchfound=="true")
		{
		  text = '';
		  var setdelimiter = "false"
		  //alert(posofid)
/**
	check if position is not first then only we will show prev option
	**/
		 if(posofid!=0)
		 {
		 text="<a href='"+arrayofid[parseInt(posofid-1)]+"'  style='text-decoration:none;font-family:arial;font-size:12px;font-weight:bold'  >Prev</a>";
         setdelimiter = "true"
		 }
		 if(arrayofid[parseInt(posofid+1)]!=undefined)
		 {
 /**
	check if position is not last and first
	**/
		 if(setdelimiter=="true"&&posofid < arrayofid.length)
		 {
		 text = text + "|";
		 }
		 
		 /**
	check if position is first
	**/ 
		 if(posofid < arrayofid.length)
		 {
		 text = text + "<a href='"+arrayofid[parseInt(posofid+1)]+"'  style='text-decoration:none;font-family:arial;font-size:12px;font-weight:bold'  >Next</a>";}
	 /**
		 print text on screen
		 **/
		 }
		//alert(text)
		$("#useforprevnext").html(text);
		
		}

		
//var cookieofprevnext = readCookie('prevnextcookieno');
//alert(cookieofprevnext.replace(/.*\,/,''))
//alert(stringtomatch);

}


/** prev and next end here **/

});
   
/** function used to show and hide left sub menu **/   

function MenuClick3(objoflevel1){
var idofobjtoshow = "#"+objoflevel1;

if($(idofobjtoshow).length>0)
{
createCookie('leftmenutoshow',objoflevel1);
var parentmenu = "span#"+readCookie('leftmenuvisible');
//alert(parentmenu)
$(parentmenu).find("span").attr("style","display:none");
$(idofobjtoshow).attr("style","display:block")
$('#pane1').jScrollPane(
						{
						showArrows:true, 
							scrollbarWidth: 12,maintainPosition:true,dragMaxHeight:78,dragMinHeight:78
						}
					);
					

}
else
{
createCookie('leftmenutoshow','');
}
//alert(readCookie('leftmenutoshow'))
}


/** function used to show and hide left sub sub menu **/   
function MenuClick1(objoflevel2)
{

var idofobjoflevel2="#"+objoflevel2

if($(idofobjoflevel2).length>0)
{
var idsofcontainer = readCookie('leftmenutoshow');
//alert(readCookie('leftmenutoshow'))
idofcontainer = idsofcontainer.split(",");
//alert("#"+idofcontainer)
$("#"+idofcontainer[0]).find("span").attr("style","display:none");
$(idofobjoflevel2).attr("style","display:block");
$('#pane1').jScrollPane(
						{
							showArrows:true, 
							scrollbarWidth: 12,maintainPosition:true,dragMaxHeight:78,dragMinHeight:78
						}
					);
				
var newvalueofleftmenutoshow = idofcontainer[0]+","+objoflevel2;
createCookie('leftmenutoshow',newvalueofleftmenutoshow);
}

//alert(readCookie('leftmenutoshow'));
}


