// JavaScript Document

$(document).ready(function() {
		
		$('#myMenu > li').bind('mouseover', openSubMenu);
		$('#myMenu > li').bind('mouseout', closeSubMenu);
		
		function openSubMenu() {
			$(this).find('ul').css('visibility', 'visible');
			$(this).find('a').css('color', '#7AC142');	
		};
		
		function closeSubMenu() {
			$(this).find('ul').css('visibility', 'hidden');	
			$(this).find('a').css('color', '#455560');
		};
		
		$('#slider').nivoSlider({
			effect: 'fade',
			prevText: '', // Prev directionNav text
	        nextText: '', // Next directionNav text
			pauseTime: 4000, // How long each slide will show
			directionNav: false, // Next & Prev navigation
			randomStart: false, // Start on a random slide
			controlNav: false, // 1,2,3... navigation
			pauseOnHover: false, // Stop animation while hovering
			});
		
		$('.connect_widget_number_cloud').hide()

});


window.onload=function(){
	
	if (document.getElementById("rotator"))
		{
			document.getElementById('r_image').style.display = 'block';
			document.getElementById('r0').style.backgroundColor = '#fff';
			document.getElementById('r0').style.color = '#455560';
			InitializeTimer();
		}

}



function getScreens(id,num) {
	
	//alert(id);
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
		document.getElementById("lightbox").innerHTML=xmlhttp.responseText;
		$('#lightbox').fadeIn('slow');
		}
	  }
	  var url = 'get_screens.php?gameid=' + id;
	  url = url + '&num=' + num;
	  //alert(url);
	xmlhttp.open('POST', url,true);
	xmlhttp.send();

}

function closeBox() {
	
	$('#lightbox').fadeOut('slow');	
	
}

function fadeScreen() {
	
	$('#lb_screen').fadeOut('slow');
	
}

function changeScreen(id,scrn,dir) {
	
	//alert('moo');
	//alert(id);
	//alert(scrn);
	//alert(dir);

	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById('lb_screen').style.display = 'none';
			document.getElementById("lb_screen").innerHTML=xmlhttp.responseText;
			$('#lb_screen').fadeIn('slow');
			
		}
	  }
	  
	  
	  
	 // var scrn = scrn;
	  
	  if(document.getElementById('screen_flag') != null){
		  
		scrn = document.getElementById('screen_flag').value;  
		  
	  }
	  
	  var url = 'get_nxtscreen.php?gameid=' + id;
	  url = url + '&scrn=' + scrn;
	  url = url + '&dir=' + dir;
	  //alert(url);
	xmlhttp.open('POST', url,true);
	xmlhttp.send();
	
}

////////////////////////////////////////////////////////////
// this is the timer control function					  //
// that controls the main page feature rotation           //
////////////////////////////////////////////////////////////

var secs
var timerID = null
var timerRunning = false
var delay = 8000
var i = 0

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    secs = 1
    StopTheClock()
    StartTheTimer()
}

function StopTheClock()
{
    if(timerRunning)
        clearInterval(timerID)
    timerRunning = false
}

function StartTheTimer()
{
	
    if (secs==0)
    {
        StopTheClock()
        // Here's where you put the actionables
		if (document.getElementById("rotator"))
		{
			
			i++
			
			if(i >3){
				
				i = 0;
				
			}
			
			rotateGet(i);
		}
		InitializeTimer();
    }
    else
    {
        secs = secs - 1
        timerRunning = true
        timerID = self.setInterval("StartTheTimer()", delay)
    }
}

//////////// this slides the rotation image ///////////////

function rotateHide(){
	
	$('#r_image').fadeOut(500);	
	
}

function rotateShow(){
	
	$('#r_image').fadeIn(500);	
	
}

/////// get rotating image from menu

function rotateGet(id) {
	
	//alert('moo');
	//alert(id);

	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=function()
	  {
	  if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			document.getElementById("r_image").style.display = "none";
			document.getElementById("rotator").innerHTML=xmlhttp.responseText;
			
			
			var i = 0;
	  
			for(i=0; i<4; i++){
			//alert(i);
			
				if(i == id){
					
					document.getElementById('r' + i).style.backgroundColor = '#fff';
					document.getElementById('r' + i).style.color = '#455560';
					
				}else{
				
					document.getElementById('r' + i).style.background = 'none';
					document.getElementById('r' + i).style.backgroundImage = 'url(images/bg_r_menu.png)';
					document.getElementById('r' + i).style.color = '#fff';
				
				}
			
			}
			
			$('#r_image').fadeIn('slow');

		}
	  }
	  
	  
	  
	  var url = 'get_rotator.php?rotateid=' + id;
	  //alert(url);
	xmlhttp.open('POST', url,true);
	xmlhttp.send();
	
}


/////// recaptcha option
var RecaptchaOptions = {
 theme : 'clean'
};




////////////////////////////////////////////////////////////
// js form validation                                     //
////////////////////////////////////////////////////////////

function checkForm(obj)
{
   var cemail='';
   var csubject='';
   var formname = obj.name;
   var badchar = /[\W_]/;
   
  // alert(formname);

	if(obj.subject)
	{
		csubject = obj.subject;
	}
	if(obj.email)
	{
		cemail = obj.email;
	}
	
	//alert(csubject.value);
	//alert(cemail.value);

if(cemail.value != null)
{
	if(trim(cemail.value) == '')
	{
		document.getElementById(formname + "_email").innerHTML = "Please enter a valid email.";
		cemail.style.backgroundColor = "#ffeded";
		if(csubject)
		{
			document.getElementById(formname + "_subject").innerHTML = "";
			csubject.style.backgroundColor = "#fff";
		}
		
		cemail.focus();
		return false;
	}
}

if(cemail.value != null)
{
	if(!isEmail(trim(cemail.value)))
	{
		if(csubject)
		{
			document.getElementById(formname + "_subject").innerHTML = "";
			csubject.style.backgroundColor = "#fff";
		}
		document.getElementById(formname + "_email").innerHTML = "Please enter a valid email address.";
		cemail.style.backgroundColor = "#ffeded";

		cemail.focus();
		return false;
	}
}

if(csubject.value != null)
{
	if(trim(csubject.value) == '')
	{
		document.getElementById(formname + "_subject").innerHTML = "Please enter a subject.";
		csubject.style.backgroundColor = "#ffeded";
		if(cemail)
		{
			document.getElementById(formname + "_email").innerHTML = "";
			cemail.style.backgroundColor = "#fff";
		}

		csubject.focus();

		return false;
	}
}
	
	
	csubject.value    = trim(csubject.value);
	cemail.value   = trim(cemail.value);
	//alert('moo');
	sendMessage();
	

	cemail.value   = '';
	cemail.style.backgroundColor = "#fff";
	document.getElementById(formname + "_email").innerHTML = "";
	csubject.value    = '';
	csubject.style.backgroundColor = "#fff";
	document.getElementById(formname + "_subject").innerHTML = "";
	document.getElementById('message').value    = '';
	
}

function trim(str)
{
   return str.replace(/^\s+|\s+$/g,'');
}

function isEmail(str)
{
   var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;

return regex.test(str);
}



//$(document).ready(function() {
//		
//		$('.myMenu > li').bind('mouseover', openSubMenu);
//		$('.myMenu > li').bind('mouseout', closeSubMenu);
//		
//		function openSubMenu() {
//			$(this).find('ul').css('visibility', 'visible');	
//		};
//		
//		function closeSubMenu() {
//			$(this).find('ul').css('visibility', 'hidden');	
//		};
//		
//		
//
//});
