$(document).ready(function() {
	document.body.className = 'gray_gradiant';

});

/*

This javascript function is already defined on line 399 of global.js


function validatePreLoginForm(frm) {

	var  flag = true;
	$('#login_loading').show();
	email = $('#email_address').val();
	password = $('#password').val();
	if(!validateEmail(email)) {
		flag = false;
		$('#email_error_message').html('<h1>Not a valid Email !</h1>');
		$('#email_error_message').show();
		tb_show('','#TB_inline?height=210&width=500&inlineId=new_home_div_id','');
		return false;
	}
	if(password.length < 6) {
		$('#email_error_message').hide();
		$('#pwd_error_message').show();
		tb_show('','#TB_inline?height=210&width=500&inlineId=new_home_div_id','');
		return false;
	}
	else {
		var dataString = "email_address="+email+'&password='+password+'&opr=new_home';
		$.ajax({
	     	type: "POST",
	      	url: "?q=user/login_submit",
	      	data: dataString,
	      	success: function(response) {
	      			if(response == 0) {
	      				$('#email_error_message').html('<h1>Either Username or password is wrong !</h1>');
	      				$('#email_error_message').show();
						tb_show('','#TB_inline?height=210&width=500&inlineId=new_home_div_id','');
	      			} else {
	      				window.location='/';
	      			}
			}
		});
	}
	return false;
}
*/


function validatePreInviteForm(frm) {
	/*inviteConfirmationObj = document.getElementById('confirmation_message');
	inviteFormObj = document.getElementById('invitation_form_container');*/

	//email = frm.invite_email.value;
	email = $('#invite_email').val();

	/*inviteFormObj.style.display = "none";
	inviteConfirmationObj.style.display = "block";*/

	if(!validateEmail(email)) {
		//alert('Enter valie E-mail Id');
		$('#log_err_invite_error').show();
		$('#email_invite_gobt').show();
		//$('#invitation_form_container').hide();
		//var str = "<a href='javascript: void(0);' onClick='showInviteForm()'>Enter valid Email Id.</a>";
		//$('#confirmation_message').html(str);
	}
	else {
		$('#go_button_container').hide();
		$('#loading_img_container').show();
		var str = "Thank you :)";
		var dataString = "email="+email;
		$.ajax({
	     	type: "POST",
	      	url: "?q=user/invitation",
	      	data: dataString,
	      	success: function(response) {
	      		$('#invite_email').hide();
	      		$('#loading_img_container').hide();
	      		$('#confirmation_message').show();
	      		$('#confirmation_message').html(str);
	      		if(response != 0) {
		        	alert(response);
		        }
			}
		});
		//inviteConfirmationObj.innerHTML = str;
	}

	return false;
}

function showInviteForm() {
	/*inviteConfirmationObj = document.getElementById('confirmation_message');
	inviteFormObj = document.getElementById('invitation_form_container');

	inviteFormObj.style.display = "block";
	inviteConfirmationObj.style.display = "none";*/
	$('#invitation_form_container').show();
	$('#confirmation_message').hide();
	$('#email_invite_loadbt').hide();


}

function hideErrorLayer(obj) {
	//document.getElementById('log_err_'+obj).style.display = "none";
	$('#log_err_'+obj).hide();
}

change_backgorund = function(game_id) {
	var path = $('#CDN_path').val();
	var total_path = path + game_id + '/bg_gamesection.jpg';
	document.body.style.background ='url('+tempImg[game_id].src+')';
}
var tempImg = [];
$(document).ready(function() {
//	var path = $('#CDN_path').val();
/*	tempImg[1] = new Image()
    tempImg[1].src = path + '/1/bg_gamesection.jpg';

	tempImg[26] = new Image()
    tempImg[26].src = path + '/26/bg_gamesection.jpg';

    tempImg[13] = new Image()
    tempImg[13].src = path + '/13/bg_gamesection.jpg';

    tempImg[15] = new Image()
    tempImg[15].src = path + '/15/bg_gamesection.jpg';

    tempImg[8] = new Image()
    tempImg[8].src = path + '/8/bg_gamesection.jpg';
*/

	$.ajax({
		url: '?q=home/get_top_three_avatar',
		success: function (response) {
			$('#top_three_avatar_div_id').html(response);
		}
	});
	$.ajax({
		url: '?q=home/get_items_for_home',
		success: function (response) {
			//alert(response)
			$('#item_store_div_id').html(response);
		}
	});
	$.ajax({
		url: '?q=home/display_games_on_home',
		success: function (response) {
			//alert(response)
			$('#game_display_slot').html(response);
		}
	});
	$.ajax({
		url: '?q=home/display_rss_feed_data',
		success: function (response) {
			//alert(response)
			$('#display_rss_anouncemt').html(response);
		}
	});

});


jQuery(document).ready(function() {
    $('#image_slider_id').show();
    $(".default .jCarouselLite").jCarouselLite({
        btnNext: ".default .next",
        btnPrev: ".default .prev"
    });
});

		var SlideShowSpeed = 8000;
		var CrossFadeDuration = 3;
		var Picture = new Array(); // don't change this
		var Caption = new Array(); // don't change this

		Picture[1]  = '/files/games/main_general.jpg';

		Picture[2]  = '/files/games/main_darkorbit.jpg';
		Picture[3]  = '/files/games/main_gladius2.jpg';
		Picture[4]  = '/files/games/main_seafight.jpg';
		

		var tss;
		var iss;
		var jss = 1;
		var pss = Picture.length-1;

		var preLoad = new Array();
		for (iss = 1; iss < pss+1; iss++){
		preLoad[iss] = new Image();
		preLoad[iss].src = Picture[iss];}




	function runSlideShow(){
		var path = $('#game_file_path').val();
		
		if (document.all){
			document.images.PictureBox.style.filter="blendTrans(duration=2)";
			document.images.PictureBox.style.filter="blendTrans(duration=CrossFadeDuration)";
			document.images.PictureBox.filters.blendTrans.Apply();
		}
		jss =	$('#jss_val').val();
		var image = preLoad[jss].src;
		
		var split_path = preLoad[jss].src.split("/");
		var split_image_for_id = split_path[5].split(".");
		if(jss>1) {
			var split_path_previous_image = preLoad[jss-1].src.split("/");
			var split_image_for_for_previous_id = split_path_previous_image[5].split(".");
			$('#'+split_image_for_for_previous_id[0]).removeClass('active');
		}
		$('#'+split_image_for_id[0]).addClass('active');


		//var new_image_path = path + split_path[3];
		var new_image_path = $('#server_path').val() + "/" + split_path[5];
		
		//document.images.PictureBox.src = new_image_path;
		document.images.PictureBox.src = image;
		if (document.all) document.images.PictureBox.filters.blendTrans.Play();
		if(jss==1) {
			var split_path_previous_image = preLoad[pss].src.split("/");
			var split_image_for_for_previous_id = split_path_previous_image[5].split(".");
			$('#'+split_image_for_for_previous_id[0]).removeClass('active');
		}
		
		jss = parseInt(jss) + 1;
		$('#jss_val').val(jss);
		if (jss > (pss)) {
			jss=1;
			$('#jss_val').val(jss);
		}
		$("#PictureBox").bind("click", function(e){
     		var find_path = $('#'+split_image_for_id[0]+'_url').val();
      		if(split_image_for_id[0] == 'main_wow') {
      			window.location='/guide?id=1';
      		}
      		else if(split_image_for_id[0] == 'main_general') {
      			window.location='/user/register';
      		}
      		else
      			window.location='/games/'+find_path;
    	});


		tss = setTimeout('runSlideShow()', SlideShowSpeed);
	}

	$(window).load(function() {
	var path = $('#game_file_path').val();
			runSlideShow(pss,jss);
	});


	change_image_container = function(image_name,id,no) {
		$('#jss_val').val(no);
		var path = $('#game_file_path').val();
		image_name = '/files/games/'+image_name;
		for(counter=1;counter<Picture.length;counter++) {
			if(Picture[counter]== image_name)
			$('#'+id).addClass('active');
			else {
				var split_image_name = Picture[counter].split("/");
				var split_image_by_dot = split_image_name[3].split(".");
				$('#'+split_image_by_dot[0]).removeClass('active');
			}

		}
		
		//var complete_image_path = path + image_name;
		var complete_image_path = $('#server_path').val() + "/" + image_name;
		$('#PictureBox').attr("src",complete_image_path);

		var find_path = $('#'+id+'_url').val();
   		if(id == 'main_wow') {
   			$('#home_level1_slider').attr('href', '/guide?id=1');
   		}
   		else if(id == 'main_general') {
   			$('#home_level1_slider').attr('href', '/user/register');
   		}
   		else {
   			$('#home_level1_slider').attr('href', '/games/'+find_path);
   		}

	}

	change_opacity_onmouseover = function(obj) {
		obj.style.opacity=.7;
		obj.filters.alpha.opacity=70;
	}
	change_opacity_onmouseout = function(obj) {
		obj.style.opacity=1;
		obj.filters.alpha.opacity=100;
	}