var middle = 3;
var pc_serialScrollNbImagesDisplayed;
var pc_serialScrollNbImages;
var pc_serialScrollActualImagesIndex;
//** pc_ must be added at line 6 and 7
function pc_serialScrollFixLock(event, targeted, scrolled, items, position){
  jQuery('#catBoxNavleft').css('cursor', position == 0 ? 'default' : 'pointer').fadeTo(500, position == 0 ? 0.0 : 1);
  jQuery('#catBoxNavright').css('cursor', position + pc_serialScrollNbImagesDisplayed == pc_serialScrollNbImages ? 'default' : 'pointer').fadeTo(500, position + pc_serialScrollNbImagesDisplayed == pc_serialScrollNbImages ? 0.0 : 1);
  return true;
}


var blockFilterClicked = 'NO';
// jQuery.noConflict(); // NOTE: for mootools
// NOTE: always add jQuery(event) instead of $event
function toggle_me(div_id)
{
	jQuery.noConflict();
	// Self JQuery in SearchBox
	jQuery('#borderblue').hide;
	if (div_id != '#filterdropdown'){
		jQuery('#filterdropdown').hide();
	}
	if (div_id != '#filterdropdown2'){
		jQuery('#filterdropdown2').hide();
	}
	if (div_id != '#filterdropdown3'){
		jQuery('#filterdropdown3').hide();
	}
	if (div_id != '#filterdropdown4'){
		jQuery('#filterdropdown4').hide();
	}	
	jQuery(div_id).toggle('blind',{},500,chk_dottedborder());		
}

function chk_dottedborder(){		
	// get the element of each dropdown in searchbox
	var x = document.getElementById("filterdropdown");
	var x2 = document.getElementById("filterdropdown2");
	var x3 = document.getElementById("filterdropdown3");
	var x4 = document.getElementById("filterdropdown4");
	jQuery.noConflict();
	jQuery('#borderblue').show();
	if (x.style.display == "block" || x2.style.display == "block" || x3.style.display == "block" || x4.style.display == "block")
	{
		jQuery('#borderblue').hide();		
	}else{
		//blockFilterClose = 'YES';
	}	
}
function hidesearch(){	
	// hide the search box in body onclick
	jQuery.noConflict();
	if (blockFilterClicked == 'NO'){
		// FIltersearch.php
		jQuery('#borderblue').hide();
		jQuery('#filterdropdown').hide();
		jQuery('#filterdropdown2').hide();
		jQuery('#filterdropdown3').hide();
		jQuery('#filterdropdown4').hide();
		jQuery('#chooseitem_absolute').hide(); // collection overview in brand_view.php
		jQuery('#white1px').hide(); // collection overview in brand_view.php
	}
	
}
function chk_dottedborder1(){		
	jQuery.noConflict();
	var x = document.getElementById("chooseitem_absolute");
	jQuery('#white1px').show();
	if (x.style.display == "block")
	{
		jQuery('#white1px').hide();
	}

}
function toggle_me1(div_id)
{
	jQuery.noConflict();
	jQuery(div_id).toggle('blind',{},500,chk_dottedborder1());		
}
function blockclicked(){
	blockFilterClicked = 'YES';
}
function blocknotclicked(){
	blockFilterClicked = 'NO';
}
// use in Product.php onmouseover
function imagedetailhide(div_id)
{
	jQuery.noConflict();
	jQuery(div_id).toggle();	
}
function imagedetailhide1(div_id)
{
	jQuery.noConflict();
	jQuery(div_id).toggle('blind');	
}
function hide(div_id)
{
	jQuery.noConflict();
	jQuery(div_id).hide();		
}
function show(div_id)
{
	jQuery.noConflict();
	jQuery(div_id).show();		
}
function hide1(div_id)
{
	jQuery.noConflict();
	jQuery(div_id).hide('blind',500);		
}
function show1(div_id)
{
	jQuery.noConflict();
	jQuery(div_id).show('blind');		
}
function addclass(removeclass,add_class,class_name)
{
	jQuery.noConflict();
	jQuery(removeclass).removeClass(class_name);
	jQuery(add_class).addClass(class_name);
}
function add_twoclass(removeclass,add_class,class_name,removeclass2,add_class2,class_name2)
{
	jQuery.noConflict();
	jQuery(removeclass).removeClass(class_name);
	jQuery(add_class).addClass(class_name);
	
	jQuery(removeclass2).removeClass(class_name2);
	jQuery(add_class2).addClass(class_name2);
}
function popup(mylink, windowname)
{
  if (! window.focus)return true;
  var href;
  if (typeof(mylink) == 'string')
     href=mylink;
  else
     href=mylink.href;
  window.open(href, windowname, 'width=900,height=600,scrollbars=yes');
  return false;
}


/* for search autocomplete used in filter search .php*/

jQuery.noConflict();
jQuery().ready(function() {
 
  jQuery('.locationajax a').click(function(){
    id = jQuery(this).attr("id");
    jQuery("#catBoxright a").removeClass("prodcatupperbold");
    jQuery("#catBoxright a[rel="+id+"]").addClass("prodcatupperbold");
    
    jQuery('#loc_id .loading').show();
    jQuery('#loc_id #change').html("");
    jQuery.ajax({
      type: "GET", 
      url: "/locationscript.php", 
      data: "content=" + id,
      cache: true,
      success: function(html){
        jQuery('#loc_id .loading').hide();
        jQuery('#loc_id #change').html(html);

      }
    });
  });
  

 
  // product detail other images
  jQuery('.imagesizehover img').click(function(){
    id = jQuery(this).attr("rel");
    parentRel = jQuery(this).parent().attr("rel");
    parentTitle = jQuery(this).parent().attr("title"); // either video or image
    check = false;
    if (parentRel == "edp1" || parentRel == "edp2")
    {
      if (parentRel == "edp1"){
        prodimg = "#edp1";
      }else{
        prodimg = "#edp2";
      }
      check = true;
      jQuery(prodimg).parent().find('.loading').show();
    }else{
      prodimg = "#prodimg";
      jQuery('#detailabsolute .loading').show();
    }
    

    jQuery(prodimg).html("");
    jQuery.ajax({
			type: "GET", 
      url: "/productdetailscript.php", 
      data: "id=" + id + "&type=" + parentTitle,
      cache: false,
			success: function(html){
        if (check == true)
        {
          jQuery(prodimg).parent().find('.loading').hide();
        }else{
          jQuery('#detailabsolute .loading').hide();
        }
				jQuery(prodimg).html(html);
				jQuery(prodimg).hide().fadeIn();

      }
    });
  });
 
	function findValueCallback(event, data, formatted) {
		//$("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
		if (!data)
		{
			// Submit it to our searchresult.php
			document.searchForm.submit();
		}else{
			// Submit it to our searchresult.php
			document.searchForm.keyword.value = formatted;
			document.searchForm.submit();
		}
	}
	jQuery("#searchField").result(findValueCallback).next().click(function() {
		jQuery(this).prev().search();
		});
			 jQuery("#searchField").autocomplete(searchdata,
				{
					max:15		
				}
			);  

  jQuery('#tfcdiv').show();  
  jQuery('#syrdiv').show();  
  jQuery('.defer').show();  
  
    
  //init the serialScroll for category
  pc_serialScrollNbImages = jQuery('#catBox li').length;
  pc_serialScrollNbImagesDisplayed = 8;
  pc_serialScrollActualImagesIndex = 0;
  jQuery('#catBox').serialScroll({
    items:'li',
    prev:'a#catBoxNavleft',
    next:'a#catBoxNavright',
    axis:'x',
    offset:0,
    stop:true,
    onBefore:pc_serialScrollFixLock,
    duration:500,
    step: 1,
    lock: false,
    force:false,
    cycle:false,
    exclude:7  // as long as category increase this should be vary
  });
  jQuery('#catBox').trigger('goto', [middle-3] );
  
  if (jQuery('.jScroll').height() > 92)
  {
    jQuery('.jScroll').height(92);
    jQuery('.jScroll').show();
     // scroller
    jQuery('.jScroll').jScrollPane({showArrows:true, scrollbarWidth: 13, arrowSize: 12, topCapHeight: 3, bottomCapHeight: 3});
  }
 

  
  
});  

 
// url + "?"
function tbshow(title,url,width,height)
{
	if (width != '')
		rWidth = width;
	else
		rWidth = screen.width - 300;
	if (height != '')
		rHeight = height;
	else
		rHeight = screen.height - 350;
	tb_show(title,url + "?keepThis=true&TB_iframe=true&height=" + rHeight + "&width=" + rWidth);
}
// url + "&"
function tbshow1(title,url,width,height)
{
	if (width != '')
		rWidth = width;
	else
		rWidth = screen.width - 300;
	if (height != '')
		rHeight = height;
	else
		rHeight = screen.height - 300;
	tb_show(title,url + "&keepThis=true&TB_iframe=true&height=" + rHeight + "&width=" + rWidth);
}
// Remaining characters left
function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update "characters left" counter
	else				
		cntfield.value = maxlimit - field.value.length;
}

//from vworker
var middle = 3;
var pc_serialScrollNbImagesDisplayed;
var pc_serialScrollNbImages;
var pc_serialScrollActualImagesIndex;
//** pc_ must be added at line 6 and 7
function pc_serialScrollFixLock(event, targeted, scrolled, items, position){
	jQuery("#catBox li").each(function(i){
		jQuery(this).show();
	});
  //jQuery('#catBoxNavleft').css('cursor', position == 0 ? 'default' : 'pointer').fadeTo(500, position == 0 ? 0.2 : 1);
  jQuery('#catBoxNavleft').css('cursor', position == 0 ? 'default' : 'pointer').fadeTo(500, position == 0 ? 0.2 : 1); 
  jQuery('#catBoxNavleft').css('background', position == 0 ? 'url("/images/nav_all.gif") no-repeat scroll 0 0 transparent' : '');
  jQuery('#catBoxNavright').css('cursor', position + pc_serialScrollNbImagesDisplayed == pc_serialScrollNbImages ? 'default' : 'pointer').fadeTo(500, position + pc_serialScrollNbImagesDisplayed == pc_serialScrollNbImages ? 0.2 : 1);
  jQuery('#catBoxNavright').css('background', position + pc_serialScrollNbImagesDisplayed == pc_serialScrollNbImages ? 'url("/images/nav_all.gif") no-repeat scroll 0 -33px transparent' : ''); 
  return true;
}


jQuery.noConflict();
jQuery().ready(function() {
  //init the serialScroll for category
  pc_serialScrollNbImages = jQuery('#catBox li').length;
  pc_serialScrollNbImagesDisplayed = 8;
  pc_serialScrollActualImagesIndex = 0;
  jQuery('#catBox').serialScroll({
    items:'li',
    prev:'a#catBoxNavleft',
    next:'a#catBoxNavright',
    axis:'x',
    offset:1,
    stop:true,
    onBefore:pc_serialScrollFixLock,
    duration:500,
    step: 1,
    lock: false,
    force:false,
    cycle:false,
    exclude:7,  // as long as category increase this should be vary
	onAfter:function(){
		stripOffTruncated();																   
	}
  });
	stripOffTruncated();	
});  


function stripOffTruncated(){
	var areaWidth  = jQuery("#catBox").width();
	var stripOff = false;
	
	jQuery("#catBox li").each(function(){
		var left = jQuery(this).children().position().left;

        var width = jQuery(this).children().width();
		//width += parseInt(jQuery(this).css("padding-left"), 10);// + parseInt(jQuery(this).css("padding-right"), 10); //Total Padding Width
		//width += parseInt(jQuery(this).css("margin-left"), 10);// + parseInt(jQuery(this).css("margin-right"), 10); //Total Margin Width
		//width += parseInt(jQuery(this).css("borderLeftWidth"), 10);// + parseInt(jQuery(this).css("borderRightWidth"), 10); //Total Border Width

		//alert("Hi")
		if(left > 0 && (left + width) > areaWidth || stripOff)
		{
			//alert(left);
			jQuery(this).hide();
			stripOff = true;
		}
	});
}

 
 
