		var generating = false;
		var lastImg = '';
		

function getUrlVars() {
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++) {
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
//	return vars;
//	if (vars['imgurl'] != undefined) {
//	document.getElementById("image").value = vars['imgurl'];
//	document.getElementById("lolcat").src = vars['imgurl'];
		if (vars['imgurl'] == "http://politiclolz.com/files/originals/500/US_Capitol.jpg") {
		document.getElementById("fontsize").value = 12;
		document.getElementById("fontsize1").value = 12;
		document.getElementById("fontsize2").value = 12;
		} else if (vars['imgurl'] == "http://politiclolz.com/files/originals/500/President_Barack_Obama_Dimitry_Medvedev_Russia_Miller_High_Life_Delivery_Guy.jpg" || vars['imgurl'] == "obamahighlife") {
			document.getElementById("fontsize").value = 24;
			document.getElementById("fontsize1").value = 24;
			document.getElementById("fontsize2").value = 12;
		}
//	}

}

		
		// set up fancy JS first	
		$(document).ready(function(){
			$('#lolcat').load(function(){
				$('#loading').html("LOL Generated!");
				setTimeout(function(){
					$('#loading').fadeOut(1000);
				},3000);
				generating = false;
			});
			$('#lolcat').error(function(){
				$('#loading').html("Error! You no get LOLCat. :(");
			});
		});
		
		function show_cat(submitted){
				document.getElementById("upload_target").src="http://politiclolz.com/wp-content/themes/PoliticLOL/lolbuilder/includes/formproc2.php?image=" + escape($("input[@name=image]").val());			
			
			if (!generating){
				if ($("input[@name=text]").val() == '' && $("input[@name=text1]").val() == '' && $("input[@name=text2]").val() == ''){
					$('#loading').fadeIn(500);
					$('#loading').html("You should specify text to display!");
					return;
				}
				
				generating = true;
				$('#loading').fadeIn(500);
				$('#loading').html("Loading LOL...");
				
				if ($("input[@name=text]").val() != "") {
					var title = $("input[@name=text]").val();
				} else if ($("input[@name=text1]").val() != "") {
					var title = $("input[@name=text1]").val();
				} else if ($("input[@name=text2]").val() != "") {
					var title = $("input[@name=text2]").val();
				} else {
					var title = "";
				}
				
				var original="";

				topmargin1 = $("input[@name=topmargin1]").val();
				leftmargin1 = $("input[@name=leftmargin1]").val();
				boxwidth1 = $("input[@name=boxwidth1]").val();
				
				topmargin2 = $("input[@name=topmargin2]").val();
				leftmargin2 = $("input[@name=leftmargin2]").val();
				boxwidth2 = $("input[@name=boxwidth2]").val();
				
				topmargin3 = $("input[@name=topmargin3]").val();
				leftmargin3 = $("input[@name=leftmargin3]").val();
				boxwidth3 = $("input[@name=boxwidth3]").val();
				
				if ($("input[@name=image]").val() == "http://politiclolz.com/files/originals/500/US_Capitol.jpg") {
				align = "tc";
				align1 = "tc";
				align2 = "tc";
				boxwidth1 = 162;
				topmargin1 = 12;
				leftmargin1 = -293;
				boxwidth2 = 162;
				topmargin2 = 48;
				leftmargin2 = 328;
				boxwidth3 = 162;
				topmargin3 = 256;
				leftmargin3 = -320;
				text_color1 = 0;
				text_color2 = 0;
				text_color3 = 0;
				shadow_color1 = 255;
				shadow_color2 = 255;
				shadow_color3 = 255;

} else if ($("input[@name=image]").val() == "http://politiclolz.com/files/originals/500/President_Barack_Obama_Dimitry_Medvedev_Russia_Miller_High_Life_Delivery_Guy.jpg") {
				align = $("input[@name=align]:checked").val();
				align1 = $("input[@name=align1]:checked").val();
				align2 = "tc";
//				boxwidth1 = 162;
//				topmargin1 = 12;
//				leftmargin1 = -293;
//				boxwidth2 = 162;
//				topmargin2 = 48;
//				leftmargin2 = 328;
				boxwidth3 = 190;
				topmargin3 = 227;
				leftmargin3 = -113;
				text_color1 = 0;
				text_color2 = 0;
				text_color3 = 0;
				shadow_color1 = 255;
				shadow_color2 = 255;
				shadow_color3 = 255;
} else {
				align = $("input[@name=align]:checked").val();
				align1 = $("input[@name=align1]:checked").val();
				align2 = $("input[@name=align2]:checked").val();
				text_color1 = $("input[@name=text_color1]").val();
				text_color2 = $("input[@name=text_color2]").val();
				text_color3 = $("input[@name=text_color3]").val();
				shadow_color1 = $("input[@name=shadow_color1]").val();
				shadow_color2 = $("input[@name=shadow_color2]").val();
				shadow_color3 = $("input[@name=shadow_color3]").val();
}
					
				
				var img = escape("http://politiclolz.com/wp-content/themes/PoliticLOL/lolbuilder/includes/img.php?align=" + align + "&text=" + $("input[@name=text]").val() + "&fontsize=" + $("input[@name=fontsize]").val() + "&num=3&boxwidth=" + boxwidth1 + "&padding=10&topmargin=" + topmargin1 + "&leftmargin=" + leftmargin1 + "&font=" + $("input[@name=font]").val() + "&text_color1=" + text_color1 + "&text_color2=" + text_color2 + "&text_color3=" + text_color3 + "&shadow_color1=" + shadow_color1 + "&shadow_color2=" + shadow_color2 + "&shadow_color3=" + shadow_color3 + "&case=" + $("input[@name=case]").val() + "&img=" + $("input[@name=image]").val() + "&seed=" + Math.floor(Math.random()*30000));

				var img1 = escape("http://politiclolz.com/wp-content/themes/PoliticLOL/lolbuilder/includes/img.php?align=" + align1 + "&text=" + $("input[@name=text1]").val() + "&fontsize=" + $("input[@name=fontsize1]").val() + "&num=2&boxwidth=" + boxwidth2 + "&padding=10&topmargin=" + topmargin2 + "&leftmargin=" + leftmargin2 + "&font=" + $("input[@name=font]").val() + "&text_color1=" + text_color1 + "&text_color2=" + text_color2 + "&text_color3=" + text_color3 + "&shadow_color1=" + shadow_color1 + "&shadow_color2=" + shadow_color2 + "&shadow_color3=" + shadow_color3 + "&case=" + $("input[@name=case]").val() + "&img=" + img + "&seed=" + Math.floor(Math.random()*30000));
				
var img2 = "http://politiclolz.com/wp-content/themes/PoliticLOL/lolbuilder/includes/img.php?align=" + align2 + "&text=" + $("input[@name=text2]").val() + "&submitted=" + submitted + "&original=" + $("input[@name=image]").val() + "&fontsize=" + $("input[@name=fontsize2]").val() + "&num=1&boxwidth=" + boxwidth3 + "&padding=10&topmargin=" + topmargin3 + "&leftmargin=" + leftmargin3 + "&font=" + $("input[@name=font]").val() + "&text_color1=" + text_color1 + "&text_color2=" + text_color2 + "&text_color3=" + text_color3 + "&shadow_color1=" + shadow_color1 + "&shadow_color2=" + shadow_color2 + "&shadow_color3=" + shadow_color3 + "&case=" + $("input[@name=case]").val() + "&orgimg=" + $("input[@name=image]").val() + "&title=" + title +"&img=" + img1;
				if (lastImg != img){
					$('#lolcat').attr("src",img2 + '&seed=' + Math.floor(Math.random()*30000));
					
					// fix possible problems with caching.. 
					setTimeout(function(){
						generating = false
						},3000
					);
				}
			}
			if(submitted=="Y") {
				alert("Thank you for your submission!");
			}
		}
		

function init2() {
	init();
	getUrlVars();
}

function init() {
	LoadGallery(1,10);
	document.getElementById('file_upload_form').onsubmit=function() {
		document.getElementById('file_upload_form').target = 'upload_target'; //'upload_target' is the name of the iframe
		document.getElementById("upload_target").onload = uploadDone; //This function should be called when the iframe has compleated loading.  That will happen when the file is completely uploaded and the server has returned the data we need.
	}
}


function uploadDone() { //Function will be called when iframe is loaded
	var ret = frames['upload_target'].document.getElementsByTagName("body")[0].innerHTML;
	
	document.getElementById("image").value = ret;
	if (document.getElementById("file").value != "") {
		document.getElementById("lolcat").src = ret;
	}
	document.getElementById("file").value = "";
}

function LoadFromGallery (imgsrc) {
	document.getElementById("image").value = imgsrc;
	document.getElementById("lolcat").src = imgsrc;
	if (imgsrc == "http://politiclolz.com/files/originals/500/US_Capitol.jpg") {
		document.getElementById("fontsize").value = 12;
		document.getElementById("fontsize1").value = 12;
		document.getElementById("fontsize2").value = 12;
	} else if (imgsrc == "http://politiclolz.com/files/originals/500/President_Barack_Obama_Dimitry_Medvedev_Russia_Miller_High_Life_Delivery_Guy.jpg" || imgsrc == "obamahighlife") {
		document.getElementById("fontsize").value = 24;
		document.getElementById("fontsize1").value = 24;
		document.getElementById("fontsize2").value = 12;	
	}
}
