/*Frame Break*/
if (top!= self){
	if (location){
		top.location.replace(self.location.href)
	}else{
		top.document.location.replace(self.document.location.href);
	}
}

/*Core Object*/
if(!window.Litewarez){var Litewarez = new Object();}
$(document).ready(function(){
	Litewarez.Sys.TableSort();
	/*Litewarez.Sys.LoadTwitter();*/
	Litewarez.Sys.InitFacebox();
	Litewarez.Sys.LoadIMBDLinks();
	Litewarez.Sys.NewWindowLinks();
	Litewarez.Sys.StartAlexa();
	Litewarez.Sys.StartAnalytics();
	Litewarez.Sys.StartQuantcast();
	Litewarez.Sys.SearchLoad();
})

var FbLiveFeedIndexLoaded = false;

/*System*/
Litewarez.Sys = {
	/*Variables*/
	DownloadTableId : "#downloads_table",	
	/*Functions*/
	DetectBrowser : function(){
		if(window.chrome && window.chrome.csi){return 'chrome'}
		if(navigator.appVersion.match(/MSIE/) == "MSIE"){return 'ie'}
		if(navigator.userAgent.match(/gecko/i)){return 'gecko';}
		if(navigator.userAgent.match(/opera/i)){return 'opera';}
		return 'ie' // Worst case
	},
	SetCookie : function(name,value,options){
		return $.lwCookie(name,value,options);
	},
	GetCookie : function(name){
		return $.lwCookie(name);
	},
	DeleteCookie : function(){
		return $.lwCookie(name,null);
	},
	StartAlexa : function(){
		/*Developer note
			Alexa requires the call to be from script as it search parent so we will create a scripttag with dynamics
		*/
		$.getScript("http://xslt.alexa.com/site_stats/js/s/a?url=www.litewarez.net",function(){
			/*Alexa Loaded*/
		});
	},
	LoadIMBDLinks : function(){
		var IMDBSearchDom = 'http://www.imdb.com/find?'
		$('a[rel*=movies]').each(
			function(k,element){
				var Title = $(element).text();
				var TableRow = $(element).parent().parent();
				$(TableRow).find('.dl_row_tools').append('<a target="_blank"  title="Lookup movie on the internet movie database" href="'+IMDBSearchDom +$.param({s:"tt",q:Title})+'"><img alt="Lookup movie on the internet movie database" src="'+ template_root +'images/pixal.png" class="misc icon_imdb_info" title="Lookup movie on the internet movie database" /></a>')
			}
		)
	},
	NewWindowLinks : function(){
		$('a[rel*=_blank]').click(function(){
			window.open(this.href);
			return false;
		})
	},
	StartQuantcast :function(){
		var qoptions={qacct:"p-beO09EbwKypeg"};
		$.getScript("http://edge.quantserve.com/quant.js")
	},
	StartAnalytics : function(){
		$.getScript((("https:" == document.location.protocol) ? "https://ssl." : "http://www.")+"google-analytics.com/ga.js",
			function(){
				var liteTracker = _gat._getTracker("UA-12164526-1");
				var snowTrackker = _gat._getTracker("UA-10137500-2");
				/*Load mine and trini's tracker*/
				liteTracker._trackPageview();
				snowTrackker._trackPageview();
				/*Track out link sfor both of us*/
				$('a[href^=http]:not("[href*=://' + document.domain + ']")').click(function() {
					liteTracker._trackPageview('/out/' + $(this).attr("href"));
					snowTrackker._trackPageview('/out/' + $(this).attr("href"));
				}
			)
		});
	},
	TableSort : function(){
		$(this.DownloadTableId).tablesorter();
	},
	LoadTwitter : function(){
		getTwitters('texttwitter',{
			id: 'Litewarez',
			count: 1,
			enableLinks: true,
			ignoreReplies: true,
			clearContents: true,
			template: 'Latest: "%text%" - <strong>%time%</strong>'
		});
	},
	SearchLoad : function(){
		var SForm = $("#top_menu_search_form");
		$("input",SForm).fadeTo('fast',0.5);
		/*$("select",SForm).fadeTo('fast',0.5);*/
		/*Hovers*/
		$("input",SForm).hover(function(){$(this).fadeTo('fast',1)},function(){$(this).fadeTo('slow',0.5)});
		/*$("select",SForm).hover(function(){$(this).fadeTo('fast',1)},function(){$(this).fadeTo('slow',0.5)});*/
		$("input[type='text']",SForm).focus();
	},
	InitFacebox : function(){
		$('a[rel*=modal]').facebox();
	},
	LoadLiveFeed : function(){
		if(FbLiveFeedIndexLoaded === false){
			$.getScript("http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php",function(){
				FB.init("9bffc54551766c43d464e37b395ca2f7", site_root + "xd_receiver.htm");
				FbLiveFeedIndexLoaded = true;
				$.facebox("<h1>Live Feed</h1><fb:live-stream width=\"400\" xid=\"IndexLiveFeed\" height=\"500\"></fb:live-stream>")
			})
		}else{
			$.facebox("<h1>Live Feed</h1><fb:live-stream width=\"400\" xid=\"IndexLiveFeed\" height=\"500\"></fb:live-stream>")
		}
	}
}