 
var j = jQuery.noConflict(); 

this.saveTid = function()
{
	var getparastr = function(strname) 
	{
		var hrefstr,pos,parastr,para,tempstr;
		hrefstr = window.location.href;
		pos = hrefstr.indexOf("?");
		parastr = hrefstr.substring(pos+1);		
		para = parastr.split("&");
		tempstr = "";
		
		for(i=0;i<para.length;i++)
		{
			tempstr = para[i];
			pos = tempstr.indexOf("=");
			if(tempstr.substring(0,pos) == strname) 
			{
				return tempstr.substring(pos+1);
			}
		}
		return '';
	}
	
	var setCookie = function(name,value,daynum,domain)
	{
		var str = name+"="+escape(value);		
		var date = new Date();
		var ms = daynum * 24 * 60 * 60 * 1000; //ΓΏ·ΦΦΣΣΠ60Γλ£¬ΓΏΓλ1000ΊΑΓλ
		date.setTime(date.getTime()+ms);
		str += "; expires="+date.toGMTString();
		str += "; domain=" + domain;

		document.cookie=str;
	}
	
	var tid = getparastr("tid");
	var useremail = getparastr("u");
	if (tid != '')	
	{
		setCookie('tid', tid, 30, '.bdstudiogames.com');		
	}
	if (useremail != '')	
	{
		if ((useremail == '[[email]]') || (useremail == '%5B%5Bemail%5D%5D'))
		{
		}
		else
		{
			setCookie('username', useremail, 365*10, '.bdstudiogames.com');		
		}
	}
};

this.imageLightBox = function()
{
	j('#detail_screenshot a').lightBox({fixedNavigation:true});
};

this.submitRating = function()
{
	var zuid = j('#zuid').attr('title');	
	
	j("#ratingblock").load('parserating.php', {'zuid':zuid}, function() 
	{
		j('.hover-star').rating({
			focus: function(value, link){    
				var tip = j('#hover-test');
				tip[0].data = tip[0].data || tip.html();
				tip.html(link.title || 'value: '+value);
			},
			blur: function(value, link){
				var tip = j('#hover-test');
				j('#hover-test').html(tip[0].data || '');
			}
		});			
	});	
	
	
	j('#submitrate').bind('click', function(){		
		
		var ratingvalue = j('.hover-star:checked').attr('value');
		
		j("#ratingblock").load('parserating.php', {'op':'additem','zuid':zuid,'ratingscore':ratingvalue}, function() {			
			j('.hover-star').rating({
				focus: function(value, link){    
					var tip = j('#hover-test');
					tip[0].data = tip[0].data || tip.html();
					tip.html(link.title || 'value: '+value);
				},
				blur: function(value, link){
					var tip = j('#hover-test');
					j('#hover-test').html(tip[0].data || '');
				}
			});			
		}); 
	
	});
	
};

this.submitComment = function()
{
	var zuid = j('#zuid').attr('title');		
	
	j("#commentsblock").load('parsecomment.php', {'zuid':zuid}, function() 
	{				
		j('table.sorttable tr:odd').addClass('trodd');
		j('table.sorttable tr:even').addClass('treven');
	});	
	
	
	j('#submitcomment').bind('click', function(){		
		
		var commentuser = j('#commentuser').attr('value');
		var commentcontent = j('#commentcontent').val();
		
		commentuser = j.trim(commentuser);
		commentcontent = j.trim(commentcontent);
		
		if ((commentuser == "") || (commentcontent == ""))
		{
			alert("Please enter your name and comment.");
			return false;
		}
		
		var bantext = new Array();
		bantext[0] = "google.com";  //added other ban text		
		
		
		for(var i = 0; i < bantext.length; i++)
			if (commentcontent.indexOf(bantext[i]) > -1) return false;		
				
		
		j("#commentsblock").load('parsecomment.php', {'op':'additem','zuid':zuid,'user':commentuser,'content':commentcontent}, function() {			
			j('table.sorttable tr:odd').addClass('trodd');
			j('table.sorttable tr:even').addClass('treven');
		}); 	
	});
	
};
 
this.screenshotPreview = function(){		
	xOffset = 25;
	yOffset = 25;
	
	var showScreen = function(event){
		this.t = this.title;
		this.title = "";	
		var key = this.t.split(" -- ");
		var gamename = key[0];
		var desc = key[1];
		var rdate = key[2];
		var gamecategory = key[3];
		
		j("body").append("<div id='poptips'><span style='font-size:15px;color:#003366;'>"+gamename+"</span><br /><br /><img src='"+ this.rel +"' /><br /><br /><span style='font-size:11px;color:black;font-weight:normal;'>"+desc+"</span><div id='releasebox'><span style='font-size:10px;color:black;font-weight:bold;'>"+rdate+"</span></div><br><div id='poptips_gamecategory'><span style='font-size:11px;color:black;font-weight:bold;'>"+gamecategory+"</span></div></div>");
		
		positionScreen(event);
	};
	
	var hideScreen = function(){
		this.title = this.t;	
		j("#poptips").remove();
	};
	
	var positionScreen = function(event){
		   
		var posY = 0;
		var dlgh = 340;
		var event = event ? event : window.event;		
		posY = event.clientY;
		if (event.pageX < 750)
		{
			if (posY + dlgh < document.documentElement.clientHeight)
			{
				j("#poptips")
				.css("position", "absolute")
				.css("top",(event.pageY + yOffset) + "px")
				.css("left",(event.pageX + xOffset) + "px")
				.css("cursor","hand")
				.fadeIn("slow");
			}
			else
			{
				j("#poptips")
				.css("position", "absolute")
				.css("top",(event.pageY - dlgh + 80) + "px")
				.css("left",(event.pageX + xOffset) + "px")
				.css("cursor","hand")
				.fadeIn("slow");
			}
				
		}
		else
		{
			if (posY + dlgh < document.documentElement.clientHeight)
			{
				j("#poptips")
				.css("position", "absolute")
				.css("top",(event.pageY + yOffset) + "px")
				.css("left",(event.pageX - xOffset - 220) + "px")
				.css("cursor","hand")
				.fadeIn("slow");	
			}
			else
			{
				j("#poptips")
				.css("position", "absolute")
				.css("top",(event.pageY - dlgh + 80) + "px")
				.css("left",(event.pageX - xOffset - 220) + "px")
				.css("cursor","hand")
				.fadeIn("slow");
			}
		}
		
	};
	
	j("a.poptips").hover(showScreen,hideScreen).mousemove(positionScreen);
	
};



// starting the script on page load
j(document).ready(function(){
	screenshotPreview();	
	
	submitRating();	
	
	submitComment();	
	
	imageLightBox();
	
	saveTid();
	
});
