var IMGTESTIMONIAL_COUNT = 14;
var imgtestimonial = null;

function init(page_type) 
{
	if(page_type!="landing")
	{
		$("#mainnav div").not("#mainnav div.o").css('display', 'none');
		imgtestimonial = Math.floor(Math.random()*IMGTESTIMONIAL_COUNT);
		rotateimgtestimonial();
		setInterval("rotateimgtestimonial()", 7000);
	}
	
	if(page_type=="faq")
	{
		$("#faq-list div").css('display', 'none');
		$("#faq-list a").not("#faq-list div a").click(function() {
			$("#faq-list div").css('display', 'none');
			$("#faq-list div#"+$(this).attr('rel')).css('display', 'block');
		});
	}
	
	var AffiliateID = getCookie("AffiliateID");
	if(AffiliateID!="")
	{
		$("a[href^='http']").not("a[href*='"+document.domain+"']").attr('href', function() {
			return this.href+((this.href.indexOf("?")==-1) ? "?" : "&")+"AffiliateID="+AffiliateID;
		});
	}
}

function getCookie(c_name)
{
	if(document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if(c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if(c_end==-1) 
			{
				c_end=document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function rotateimgtestimonial()
{
	imgtestimonial=(imgtestimonial+1)%IMGTESTIMONIAL_COUNT;
	$("#imgtestimonial img").attr('src', '/img/imgtestimonial/'+imgtestimonial+'.gif');
	// clever preload if I do say so myself.
	$("#imgtestimonial").attr('background-image', 
		'url(/img/imgtestimonial/'+((imgtestimonial+1)%IMGTESTIMONIAL_COUNT)+'.gif)');
}

function showmore(c0,c1)
{
	for(i=c0;i<c1;i++)
	{
		if($('#t'+i).length == 0)
		{
			$('#more').css('display', 'none');
			return;
		}
		$('#t'+i).addClass("x");
		$('#ti'+i).attr("src", 
			$('#ti'+i).attr("src").replace('loading.gif', $('#ti'+i).attr("alt")+".jpg"));
	}
	$('#more a').attr('href', 'javascript:showmore('+c1+','+(c1*2)+');');
}
