$(document).ready(function(){

	$("div.perfBox div.buttons img").hover(function(){
		var tmp = $(this).attr('src').split("_");
		$(this).attr('src', tmp[0] +'_over.png');
	},function(){
		var tmp = $(this).attr('src').split("_");
		$(this).attr('src', tmp[0] +'_off.png');
	});

	$("#searchAgeMinMax").click(ageSumit);
});

function ageSumit()
{
	var ageMin = $("select[name='ageMin']").val();
	var ageMax = $("select[name='ageMax']").val();
	var url = $("input[name='ageUrl']").val();
	url =	url.replace(/ageMin/, ageMin);
	url =	url.replace(/ageMax/, ageMax);
	document.location.href = url;
}

function submitSearch()
{
	var args='&do=search';
	$.each($("#cam_search :checked"), function(i,el){
		if($(el).attr("value") != '')
		{
			args = args +'&'+$(el).attr("name")+'[]='+$(el).attr("value");
		}
	});
	var url = $("#cam_search input[name='action']").val();
	if(url.indexOf("?") != -1) url = url + args;
	else url = url +'?'+ args.substring(1);
	document.location.href=url;
}


function addChat(url, sessionId, appId)
{
	var flashvars = {
		t: Math.floor(Math.random()*1000000000),
		sessionId: sessionId,
		appId: appId
	};

	var params = {
		allowScriptAccess: 'always',
		allowNetworking: 'all'
	};

	var attributes = false;

	$.swfobject.embedSWF(url, "visitorChat", "100%", "100%", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
}

function openChat(url)
{
	var id = 'Chat'+ Math.floor(Math.random()*1000000000);
	var width  = screen.width - 50;
	var height = screen.height - 50;
	var left   = (screen.width  - width)/2;
	var top    = (screen.height - height)/2;
	var params = 'width='+width+', height='+height;
	params += ', top='+top+', left='+left;
	params += ', directories=no';
	params += ', location=no';
	params += ', menubar=no';
	params += ', resizable=yes';
	params += ', scrollbars=no';
	params += ', status=no';
	params += ', toolbar=no';
	newwin = window.open(url, id, params);
	if (window.focus) { newwin.focus(); }
	return false;
}


function checkSize(o)
{
	if(o) return;
	maximize(window);
}

function maximize(wnd)
{
	var scr_w = wnd.screen.availWidth;
	var scr_h = wnd.screen.availHeight;

	pref_w = scr_w;
	pref_h = scr_h;

	var winW;
	var winH;

	var x = 0;
	if (self.innerHeight)
	{
		x = self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		x = document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		x = document.body.clientWidth;
	}


	if (self.innerHeight)
	{
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		y = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		y = document.body.clientHeight;
	}

	var real_w = x;
	var real_h = y;

	var pos_x = 0;
	var pos_y = 0;

	if (real_w < pref_w || real_h < pref_h )
	{
		wnd.moveTo(pos_x, pos_y);
		wnd.resizeTo(scr_w, scr_h);
	}
}

function checkCamOpen(sessionId)
{
	if(sessionId != '')
	{
		var url = "http://www.livemaster.nl/webcams/alive_session.php?session_id="+ sessionId;

		$.ajax({
			type: "GET",
			url: url,
			dataType: "script",
			complete: function()
			{
				setTimeout(function(){
					checkCamOpen(sessionId);
				}, 3000);
			}
		});
	}
}


function openSupport(url)
{
	var width  = 650;
	var height = 450;
	var left   = (screen.width  - width)/2;
	var top    = (screen.height - height)/2;
	var params = 'width='+width+', height='+height;
	params += ', top='+top+', left='+left;
	params += ', directories=no';
	params += ', location=no';
	params += ', menubar=no';
	params += ', resizable=yes';
	params += ', scrollbars=no';
	params += ', status=no';
	params += ', toolbar=no';
	newwin = window.open(url,'SupportChat', params);
	// if (window.focus) { newwin.focus(); }
	return false;
}

function openSupportOffline()
{
	var url = siteUrl +"webcam/userReport/";
	
	var width  = 650;
	var height = 350;
	var left   = (screen.width  - width)/2;
	var top    = (screen.height - height)/2;
	var params = 'width='+width+', height='+height;
	params += ', top='+top+', left='+left;
	params += ', directories=no';
	params += ', location=no';
	params += ', menubar=no';
	params += ', resizable=yes';
	params += ', scrollbars=no';
	params += ', status=no';
	params += ', toolbar=no';
	window.open(url,'Report', params);
	return false;
}