var video = new Array();
var interval;

function cycleNext(code) {	
	var i=video[code];			
	video[code]++;
	i=video[code];	
	if(i >= video[code+'_screencaps'].length) {
		i=0;
		video[code]=0;
	}
	document.getElementById(code).src=video[code+'_screencaps'][i];		
}

function cycleStart(code) {
	interval = setInterval("cycleNext('"+code+"')", 500);	
}

function cycleBack(code) {
	clearInterval(interval);
	video[code]=0;
	document.getElementById(code).src=video[code+'_screencaps'][0];	
}

function gi_setCookie(name, value, expire_days) {
	var ex_date = new Date();
	ex_date.setDate(ex_date.getDate()+expire_days);
	document.cookie = name+"="+escape(value)+
		((ex_date==null) ? "" : ";expires="+ex_date.toGMTString());
}

function gi_getCookie(name) {
	if(document.cookie.length > 0) {			
		start = document.cookie.indexOf(name+"=");
		if(start != -1) {
			start = start+(name.length+1);
			var end = document.cookie.indexOf(";", start);
			if(end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(start,end));
		}
	}
	return "";
}

$(document).ready(function() {	
	var bindBehaviors = function(scope) {			
		$('.conversiontrack').click(function() {
			$.post("/track.php", {id:$(this).attr("id"), type:"1"});			
		});
	
		$('.clicktrack').click(function() {			
			$.post("/track.php", {id:$(this).attr("rel"), type:"2"});			
		});		
		
		$('.auto-select').focus(function() {
			this.select();
		});
		
		if(gi_getCookie("cwv") != 1) {
			pageTracker._trackPageview('/popup');
			/*var win1 = window.open("http://camwithher.com/affiliates.php?camId=1886126&memId=1795567", 'p1', 'menubar=yes, toolbar=yes, scrollbars=yes, resizable=yes, width=1024, height=768, top=10, left=10');
			win1.blur();
			window.focus();*/
			gi_setCookie("cwv", 1, 1);
		}
		$('#pxl').hide();

	}
	bindBehaviors();
});