/////////////
var t = 0;
var s = 1806;	// total width
var w = 301;	
var move = 'next';			
var totalitems = s/w;

function animate (){
		var ts = s-1;
		// check which direction to move
		if(move == "next"){
			t = (t>=ts) ? ts : t+1;	
		} else {
			t = t-1;
		};		

		// check if max
		if(t >= totalitems) {
			t = t - 2;
			move = 'prev';
		}
		// check if min
	    if(t < 0) {
			t = t +2;
			move = 'next';
		}

		p = (t*w*-1);		
		$("#sliderlist",obj).animate(
			{ marginLeft: p }, 
			800
		);	

	};

    $(document).ready(function(){	
		if ( $("#slider").length > 0 ) {
    		$("#slider").easySlider();
			var interval = setInterval(animate, 7000);
		}
	});
	
/////////////
function shuffle( inputArr ) {
	var valArr = [];
	var k = '', i = 0;
        
	for (k in inputArr) { // Get key and value arrays
		valArr.push(inputArr[k]);
		delete inputArr[k];
	}
	valArr.sort(function() {return 0.5 - Math.random();});
        
	for (i = 0; i < valArr.length; i++) { // Repopulate the old array
		inputArr[i] = valArr[i];
	}              
	return true;
}	

$(function() {
	$.getJSON("/search/keywords?language=EN", function(data){
		var tags = new Array();
		var i = 0;
		var highest = 0;
		var lowest = 0;

		$.each(data, function(tag, item){
			tags[i] = tag;
			if (parseInt(item) > parseInt(highest)) highest = item;
			if (parseInt(lowest) == 0) lowest = item;
			else if (parseInt(item) < parseInt(lowest)) lowest = item;
			i++;
		});

		highest = highest - lowest;

		$.each(data, function(tag,item) {
			data[tag] = Math.round(((item - lowest) / highest) * 4) + 1;
		});

		// slice the best 20 
		tags = tags.slice(tags.length - 20);
		shuffle(tags);
		$.each(tags, function(i,item){		
			$("<span class='tag" + data[item] + "'><a href='/search?query=" + item + "'>" + item + "</a> </span>").appendTo("#cloud");
		});

		var cloudhtml = $('#cloud').html();
		$('#cloud2').html(cloudhtml);
	});
});

/////////////
    $(function()
    {
    	$('.scroll-pane').jScrollPane({scrollbarWidth: 8, arrowSize: 16});
    });

    Cufon.replace('h1', {
    	textShadow: '#000 1px 1px'			
    });
    Cufon.replace('h2', {
    	textShadow: '#000 1px 1px'			
    });		
    Cufon.replace('h3', {
    	textShadow: '#000 1px 1px'			
    });
    Cufon.replace('a.menu',{
    	hover: true
    });
    Cufon.replace('a.menuselected');
    Cufon.replace('a.menusubselected');		
    Cufon.replace('span.title');		
    Cufon.replace('span.title2');
    Cufon.replace('a.title2');						
    Cufon.replace('a.footerbutton');			
    Cufon.replace('span.titleproducts');	
    Cufon.replace('span.title3');						
    Cufon.replace('span.noprods');

    Cufon.now();		


//////////////////
//
// functionality to open rel external links in a new window
// this is for documenttype strict where you can't use target blank
//
function externalLinks() { 
  var anchors = $("a");
  for (var i=0; i<anchors.length; i++) {
    var anchor = anchors[i];
    // check if external
    if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external"){
        anchor.target = "_blank";
    }
  }
}

///////////////////
// window functions
window.onload = function() {
  //setFooter();
  externalLinks();
    	$('.scroll-pane').jScrollPane({scrollbarWidth: 8, arrowSize: 16});
}

window.onresize = function() {
  //setFooter();
}


