/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	//alert(id);
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		document.getElementById('backgroundPopup').oncontextmenu = mischandler;
		document.getElementById('popupContact').oncontextmenu = mischandler;
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
		//if(tx=='what')
		//	document.getElementById('popup').innerHTML = '<table><tr><td align="center" style="width:540px;"><span style="font-size:20px;">IKAAILAND</span></td></tr></table>';	
		//else
		//	submit();	

	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled

	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
		loadflash();
	}
}
function loadflash(){
	var geturl = window.location.href;
	var str = geturl.split("?");
	document.getElementById("flashContent").innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="775" height="570" id="spot-the-state" align="middle"><param name="movie" value="spot-the-state.swf" /><param name="wmode" value="transparent" /><param name="quality" value="high" /><param name="bgcolor" value="#b6e2f6" /><param name="play" value="true" /><param name="loop" value="true" /><param name="wmode" value="window" /><param name="scale" value="showall" /><param name="menu" value="true" /><param name="devicefont" value="false" /><param name="salign" value="" /><param name="allowScriptAccess" value="sameDomain" /><param name=FlashVars value="'+str['1']+'" /><!--[if !IE]>--><object type="application/x-shockwave-flash" data="spot-the-state.swf" width="775" height="570"><param name="movie" value="spot-the-state.swf" /><param name="wmode" value="transparent" /><param name="quality" value="high" /><param name="bgcolor" value="#b6e2f6" /><param name="play" value="true" /><param name="loop" value="true" /><param name="wmode" value="window" /><param name="scale" value="showall" /><param name="menu" value="true" /><param name="devicefont" value="false" /><param name="salign" value="" /><param name="allowScriptAccess" value="sameDomain" /><param name=FlashVars value="'+str['1']+'" /><!--<![endif]--><a href="http://www.adobe.com/go/getflash"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a><!--[if !IE]>--></object><!--<![endif]--></object>';
}

//centering popup
function centerPopup(){
	//request data for centering
//	var windowWidth = document.documentElement.clientWidth;
//	var windowHeight = document.documentElement.clientHeight;
//	var popupHeight = $("#popupContact").height();
//	var popupWidth = $("#popupContact").width();
//	//centering
//	//alert(windowHeight);
//	//alert(popupHeight);
//	//alert(document.body.scrollTop);
//	$("#popupContact").css({
//		"position": "absolute",
//		"top": windowHeight/2-popupHeight/2,
//		"left": windowWidth/2-popupWidth/2
//	});
//	//only need force for IE6
//	
//	$("#backgroundPopup").css({
//		"height": windowHeight
//	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	//$("#button").click(function(){
		//centering with css
		//centerPopup();
		//load popup
	//	loadPopup();
	//});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});

function submit()
{
	chosen = "";
	len = document.form1.radio_btn.length;
	for (i = 0; i <len; i++) 
		if (document.form1.radio_btn[i].checked) 
			chosen = document.form1.radio_btn[i].value;
	if (chosen == "")
		document.getElementById('popup').innerHTML = '<table><tr><td align="center" style="width:540px;"><span style="font-size:20px;">Now this is just Rude, Please select your option before you hit Vote.</span></td></tr></table>';	
	else 
		ajaxcall(chosen);
	
}
function ajaxcall(chosen)
{
	url="http://www.sl8.in/controversy/vote.php?id="+chosen;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		req=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		req=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (req)
		req.onreadystatechange = function()
		{
			if (req.readyState == 4 && req.status == 200)
			{
				document.getElementById('popup').innerHTML=req.responseText;
				setTimeout("drawChart()",1500);
				//alert(req.responseText);
			}
		}

	else 
		alert("There was a problem while using XMLHTTP:\n" + req.statusText+req.responseText);
	req.open("GET",url, true);
	req.send(null);
}
function getmap(id)
{
	url="http://www.sl8.in/controversy/getmap.php?id="+id;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		req=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		req=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (req)
		req.onreadystatechange = function()
		{
			if (req.readyState == 4 && req.status == 200)
			{
				document.getElementById('map-box1').innerHTML=req.responseText;
				for(var i=1;i<8;i++)
				{
					if(i==id)
						document.getElementById(i).style.color="#393939";
					else
						document.getElementById(i).style.color="#FFFFFF";
				}
				//alert(req.responseText);
			}
		}

	else 
		alert("There was a problem while using XMLHTTP:\n" + req.statusText+req.responseText);
	req.open("GET",url, true);
	req.send(null);
}
function drawChart() {
  var jsonData = $.ajax({
	  url: "http://www.sl8.in/controversy/getData.php",
	  dataType:"json",
	  async: false
	  }).responseText;

  // Create our data table out of JSON data loaded from server.
  var data = new google.visualization.DataTable(jsonData);

  // Instantiate and draw our chart, passing in some options.
  var chart = new google.visualization.ColumnChart(document.getElementById('charts'));
  chart.draw(data, {width: 250, height: 250});
}
