/*
** Javascript: surfride.com Filter Tags
** Author: Elevator Marketing Store www.elevatorms.com
** Date: 2010
*/

$(document).ready(function() {
	$('.productTagGroup').mouseover(function() {
		$(this).next().next().addClass('selectionBoxActive');
		$(this).parent().css('z-index','200');
	});
		
	$('.productTagGroup').mouseout(function() {
		$(this).next().next().removeClass('selectionBoxActive');		  
		$(this).parent().css('z-index','0');
	});
	
	$('.productTagSelectionWrapOuter').mouseover(function() {
		$(this).addClass('selectionBoxHover');
		$(this).parent().css('z-index','200');
	});

	$('.productTagSelectionWrapOuter').mouseleave(function() {
		//var tmpThis=$(this);
		//setTimeout(function(){
	  		$(this).removeClass('selectionBoxHover');
			$(this).parent().css('z-index','0');
		//},1000);
	});
		
	var checkHeight=$('.productTagSelectionWrapOuter');
	for (i=0;i<checkHeight.length;i++) {
		if ($(checkHeight[i]).height()>300) {
			var prevWidth=$(checkHeight[i]).width();
			var newWidth=prevWidth+20;
			$(checkHeight[i]).children('ul').children('li').width(prevWidth);
			$(checkHeight[i]).children('ul').width(newWidth);
			$(checkHeight[i]).children('ul').height(300);
			$(checkHeight[i]).children('ul').css('overflow','auto');
		}
	}	
});

//truncate the selected tag
var len = 12;
var shortTag = $('a');
for (i=0;i<shortTag.length;i++) {
    if ($(shortTag[i]).parent().hasClass('truncate')) {
    	var trunc = $(shortTag[i]).html();
    	if (trunc.length > len) {
    	    trunc = trunc.substring(0, len);
    	    trunc = trunc.replace(/\w+$/, '');
    	    trunc += '...';
    	    shortTag[i].innerHTML = trunc;
    	}
    }
}


// get url parameters
$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});

// Getting URL parameters
//tags
for (i=1;i<=15;i++){
    var arrTag='';
    var byName = $.getUrlVar('tg'+[i]+'v');
    if(!byName){continue}
    arrTag=byName.split('|');
    for (tN=0;tN<arrTag.length-1;tN++) {
    	if(arrTag[tN]){
    		$('#selectedTagLi'+arrTag[tN]).css('display','block');
    		$('#selectedTagLi'+arrTag[tN]+'> a').removeClass('productTagSelection');
    		$('#selectedTagLi'+arrTag[tN]+'> a').addClass('productTagSelected');
    	}
    }
    document.getElementById('selectedTagLi'+arrTag[1]).parentNode.style.display='block';
	document.getElementById('selectedTagLi'+arrTag[1]).parentNode.parentNode.style.display='block';
}


// brands
var arrBrand='';
var byBrandName = $.getUrlVar('b');
if (byBrandName) {
	if (byBrandName.indexOf('|')!=-1) {
    	arrBrand=byBrandName.split('|');
    	for (bN=0;bN<arrBrand.length-1;bN++) {
    	    if(arrBrand[bN]){
    	    	arrBrand[bN].replace("'","\'");
    	    	$('#selectedTagLi'+arrBrand[bN]).css('display','block');
    	    	$('#selectedTagLi'+arrBrand[bN]+'> a').removeClass('productTagSelection');
    	    	$('#selectedTagLi'+arrBrand[bN]+'> a').addClass('productTagSelected');
    	    }
    	}
    	arrBrand[bN].replace("'","\'");
    	document.getElementById('selectedTagLi'+arrBrand[1]).parentNode.style.display='block';
    	document.getElementById('selectedTagLi'+arrBrand[1]).parentNode.parentNode.style.display='block';
	}
}

// selFilterBy1
var arrFB1='';
var byFB1 = $.getUrlVar('selFilterby1');
if (byFB1) {
	if (byFB1.indexOf('|')!=-1) {
    	arrFB1=byFB1.split('|');
    	for (f1N=0;f1N<arrFB1.length-1;f1N++) {
    	    if(arrFB1[f1N]){
    			arrFB1[f1N]=arrFB1[f1N].replace("%27","");
    			arrFB1[f1N]=arrFB1[f1N].replace(".","");
    			arrFB1[f1N]=arrFB1[f1N].replace("'","");
    			arrFB1[f1N]=arrFB1[f1N].replace("/","");
    			arrFB1[f1N]=arrFB1[f1N].replace("%20","");
    	    	$('#selectedTagLi'+arrFB1[f1N]).css('display','block');
    	    	$('#selectedTagLi'+arrFB1[f1N]+'> a').removeClass('productTagSelection');
    	    	$('#selectedTagLi'+arrFB1[f1N]+'> a').addClass('productTagSelected');
    	    }
    	}
    	arrFB1[1]=arrFB1[1].replace("%27","");
    	if (document.getElementById('selectedTagLi'+arrFB1[1])) {
    		document.getElementById('selectedTagLi'+arrFB1[1]).parentNode.style.display='block';
    		document.getElementById('selectedTagLi'+arrFB1[1]).parentNode.parentNode.style.display='block';
    	}
	}
}

// selFilterBy2
var arrFB2='';
var byFB2 = $.getUrlVar('selFilterby1');
if (byFB2) {
	if (byFB2.indexOf('|')!=-1) {
    	arrFB2=byFB2.split('|');
    	for (f2N=0;f2N<arrFB2.length-1;f2N++) {
    	    if(arrFB2[f2N]){
    			arrFB1[f2N]=arrFB1[f2N].replace("%27","");
    			arrFB1[f2N]=arrFB1[f2N].replace(".","");
    			arrFB1[f2N]=arrFB1[f2N].replace("'","");
    			arrFB1[f2N]=arrFB1[f2N].replace("/","");
    			arrFB1[f2N]=arrFB1[f2N].replace("%20","");
    	    	$('#selectedTagLi'+arrFB2[f2N]).css('display','block');
    	    	$('#selectedTagLi'+arrFB2[f2N]+'> a').removeClass('productTagSelection');
    	    	$('#selectedTagLi'+arrFB2[f2N]+'> a').addClass('productTagSelected');
    	    }
    	}
    	arrFB2[1]=arrFB2[1].replace("%27","");
    	if (document.getElementById('selectedTagLi'+arrFB2[1])) {
    		document.getElementById('selectedTagLi'+arrFB2[1]).parentNode.style.display='block';
    		document.getElementById('selectedTagLi'+arrFB2[1]).parentNode.parentNode.style.display='block';
		}
	}
}

