//LazyLoad 5 Oct 2010
LazyLoad=function(){function r(c,b){c=i.createElement(c);var a;for(a in b)b.hasOwnProperty(a)&&c.setAttribute(a,b[a]);return c}function k(c){var b=h[c],a,e;if(b){a=b.callback;e=b.urls;e.shift();l=0;if(!e.length){if(a)a.call(b.context||window,b.obj);h[c]=null;j[c].length&&m(c)}}}function w(){if(!d){var c=navigator.userAgent,b=parseFloat,a;d={gecko:0,ie:0,opera:0,webkit:0};if((a=c.match(/AppleWebKit\/(\S*)/))&&a[1])d.webkit=b(a[1]);else if((a=c.match(/MSIE\s([^;]*)/))&&a[1])d.ie=b(a[1]);else if(/Gecko\/(\S*)/.test(c)){d.gecko=1;if((a=c.match(/rv:([^\s\)]*)/))&&a[1])d.gecko=b(a[1])}else if(a=c.match(/Opera\/(\S*)/))d.opera=b(a[1])}}function m(c,b,a,e,s){var n=function(){k(c)},o=c==="css",f,g,p;w();if(b){b=b.constructor===Array?b:[b];if(o||d.gecko&&d.gecko<2||d.opera)j[c].push({urls:[].concat(b),callback:a,obj:e,context:s});else{f=0;for(g=b.length;f<g;++f)j[c].push({urls:[b[f]],callback:f===g-1?a:null,obj:e,context:s})}}if(!(h[c]||!(p=h[c]=j[c].shift()))){q=q||i.head||i.getElementsByTagName("head")[0];b=p.urls;f=0;for(g=b.length;f<g;++f){a=b[f];a=o?r("link",{charset:"utf-8","class":"lazyload",href:a,rel:"stylesheet",type:"text/css"}):r("script",{charset:"utf-8","class":"lazyload",src:a});if(d.ie)a.onreadystatechange=function(){var t=this.readyState;if(t==="loaded"||t==="complete"){this.onreadystatechange=null;n()}};else if(o&&(d.gecko||d.webkit))if(d.webkit){p.urls[f]=a.href;u()}else setTimeout(n,50*g);else a.onload=a.onerror=n;q.appendChild(a)}}}function u(){var c=h.css,b;if(c){for(b=v.length;--b;)if(v[b].href===c.urls[0]){k("css");break}l+=1;if(c)l<200?setTimeout(u,50):k("css")}}var i=document,q,h={},l=0,j={css:[],js:[]},v=i.styleSheets,d;return{css:function(c,b,a,e){m("css",c,b,a,e)},js:function(c,b,a,e){m("js",c,b,a,e)}}}();

function returnDocument() {	// Returns the HTML file name without domain or GET variables
	var file_name = document.location.href;
	var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
	return file_name.substring(file_name.lastIndexOf("/")+1, end);
}

function linkTrak(obj, action, label) {	// Analytics event tracking for link clicks
	var lnk, category;
	lnk = obj.href;
	category = 'Link Clicks';
	if (lnk.indexOf("iloveagoodstory.com") == -1) {action = '(ext) ' + action;}
	if (label != null || label !== '') {_gaq.push(['_trackEvent', category, action, label]);} else {_gaq.push(['_trackEvent', category, action]);}
}

function clearEmail() {
	var e = document.getElementById('txt_Email');
	if (e.value == "enter your email address here...") {e.value = "";}
}

function enrollEmail() {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var e = document.getElementById('txt_Email');
	if (reg.test(e.value) == false) {
		alert("Please enter a valid email address.");
		_gaq.push(['_trackEvent', 'Email Updates', 'Failed Validation', e.value]);
	} else {
		var url = "_subscribe.php";
		var params = "a=" + e.value;
		_gaq.push(['_trackEvent', 'Email Updates', 'Success', e.value]);
		var http = new XMLHttpRequest();
		http.open("POST", url, true);

		//Send the proper header information along with the request
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http.setRequestHeader("Content-length", params.length);
		http.setRequestHeader("Connection", "close");
		/*http.onreadystatechange = function() { //Call a function when the state changes.
			if (http.readyState == 4 && http.status == 200) {alert(http.responseText);}
		}*/
		http.send(params);
		
		document.getElementById('signupForm').style.display = 'none';
		document.getElementById('signupThanks').style.visibility = 'visible';
	}
}

switch(returnDocument()) {	// Dynamic script dependency loading & Analytics tracking
	case 'about.php':
		//LazyLoad.js('js/flexcroll.js', function () {});
		var _gaq = _gaq || []; 
		_gaq.push(['_setAccount', 'UA-5103357-12']);
		_gaq.push(['_setCustomVar', 1, 'Section', 'About_ILAGS', 3]);
		_gaq.push(['_trackPageview']);
	
		(function() {
			var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
			ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
		})();
		break;

	case 'contact.php':
		//LazyLoad.js('js/flexcroll.js', function () {});
		var _gaq = _gaq || []; 
		_gaq.push(['_setAccount', 'UA-5103357-12']);
		_gaq.push(['_setCustomVar', 1, 'Section', 'Contact_Information', 3]);
		_gaq.push(['_trackPageview']);
	
		(function() {
			var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
			ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
		})();
		break;

	case '':
	case 'index.php':
		LazyLoad.js(['js/swfobject.js', 'js/player-index.min.js'], function () {});
		var _gaq = _gaq || [];
		_gaq.push(['_setAccount', 'UA-5103357-12']);
		_gaq.push(['_setCustomVar', 1, 'Section', 'Site_Index', 3]);
		_gaq.push(['_trackPageview']);
	
		(function() {
			var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
			ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
		})();
		break;

	case 'performers.php':
		//LazyLoad.js('js/flexcroll.js', function () {});
		var _gaq = _gaq || [];
		_gaq.push(['_setAccount', 'UA-5103357-12']);
		_gaq.push(['_setCustomVar', 1, 'Section', 'List_of_Performers', 3]);
		_gaq.push(['_trackPageview']);
	
		(function() {
			var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
			ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
		})();
		break;

	case 'profile.php':
		LazyLoad.js(['js/swfobject.js', 'js/player-profile.min.js'], function () {});
		//LazyLoad.js('js/flexcroll.js', function () {});
		LazyLoad.js(['js/jquery-1.4.2.min.js', 'js/greybox.min.js'], function () {
			var GB_ANIMATION = true;
			$(document).ready(function(){
				$("a.greybox").click(function(){
					var t = this.title || $(this).text() || this.href;
					GB_show(t,this.href,700,600);
					return false;
				});
			});	
		});

		var _gaq = _gaq || []; 
		_gaq.push(['_setAccount', 'UA-5103357-12']);
		_gaq.push(['_setCustomVar', 1, 'Section', 'Performer_Profile', 3]);
		_gaq.push(['_setCustomVar', 2, 'Performer_Profile', pName, 3]);
		_gaq.push(['_trackPageview']);
	
		(function() {
			var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
			ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
		})();
		break;

	case 'transcript.php':
		var _gaq = _gaq || [];
		_gaq.push(['_setAccount', 'UA-5103357-12']);
		_gaq.push(['_setCustomVar', 1, 'Section', 'Story_Transcript', 3]);
		_gaq.push(['_setCustomVar', 2, 'Story', sID, 3]);
		_gaq.push(['_trackPageview']);
	
		(function() {
			var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
			ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
			var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
		})();
		break;

	default:
}
