//$.ui.dialog.defaults.bgiframe = true;

function showLogin() {
		$("#dialog").dialog('open');
		//$("#frm_login").find("[name=username],[name=password],[name=submit]").attr('disabled',false);
		//$('#loginMessageFailure,#loginMessagesuccess').hide();
}

function bannerShowVideo(url){

	var height 	= $('#homepageBanner').height();
	var width 	= $('#homepageBanner').width();
	var top 	= document.getElementById('homepageBanner').offsetTop;
	var left 	= document.getElementById('homepageBanner').offsetLeft;
	var newObject='';
	var src 	= '';
	
	if (url.match(/<object/i)){
		if ($(url).children('embed').length > 0)src = $(url).children('embed').attr("src");	
	}else if (url.match(/<embed/i)){
		if ($(url).attr('src') != '')src = $(url).attr("src");
	}
	
	if (src == ''){
		return false;
	}else{
		newObject = '<object width="'+width+'" height="'+height+'"><param name="movie" value="'+src+'"></param><param name="allowFullScreen" value="true"></param><param name="wmode" value="opaque"><param name="allowscriptaccess" value="always"></param><embed width="'+width+'" height="'+height+'" src="'+src+'" wmode="opaque" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true"></embed></object>';
	}

	$('#homepageBanner').append($("<div id='myflashplayer' style='width:"+width+"px;height:"+height+"px; position:absolute;left:"+left+"px;top:"+top+"px;cursor:pointer;'><img id='closeBtn' src='"+closeImg+"' style=' position:absolute;z-index:0;'  align='left' />"+newObject+"</div>"));

	$('#closeBtn').click(function(){$(this).parent().remove();}).mouseover(function(){$(this).attr("src",closeImgOver);}).mouseout(function(){$(this).attr("src",closeImg);});

	
	
	//.replace(/embed /gi, "embed wmode=\"opaque\" ")
	/*
	if ($('#myflashplayer').children("object").length > 0){
		$('#myflashplayer').children("object").width(width).children("embed").width(width);	
		$('#myflashplayer').children("object").height(height).children("embed").height(height);
	}else{
            $('#myflashplayer').children("embed").width(width);	
	    $('#myflashplayer').children("embed").height(height);	
	}

	$('#closeBtn').click(function(){$(this).parent().remove();}).mouseover(function(){$(this).attr("src",closeImgOver);}).mouseout(function(){$(this).attr("src",closeImg);});

	
	/*
	$('#homepageBanner').qtip({
		 content	: "<div id='myflashplayer'>"+url+"</div>" , 
		 position	: 'center', 
		 
		 show		:{
						when: false, // Don't specify a show event
						ready: true // Show the tooltip when ready
					},
         hide		: false,
		 style		:{
				"z-index":0,
				color	:false,
				padding	:'0px',
				margin	:'0px' ,
				width 	:$('#homepageBanner').width(),
				height 	:$('#homepageBanner').height()
			}
	});

	$('#myflashplayer').width($('#homepageBanner').width()).children("embed").width($('#homepageBanner').width());
	$('#myflashplayer').height($('#homepageBanner').height()).children("embed").height($('#homepageBanner').height());
	
*/
}

function login() {
	$("#frm_login").find("[name=username],[name=password],[name=submit]").attr('disabled',true);
	$('#loginMessageFailure,#loginMessagesuccess').hide();
	$('#loginLoader').show();
	$.ajax({
		url: "index.php?pg=login&disable_rewrite=1",
		type:"POST",
		async: true,
		dataType:'json',
		data: {
			plain:1,
			lang:g_lang_code,
			username:$("#frm_login").find("[name=username]").val(),
			password:$("#frm_login").find("[name=password]").val()
		},
		beforeSend: function(XMLHttpRequest) {
		},
		success: function(json){
			if(json.err) {
				$('#loginMessageFailure').html(json.msg).show();
			}else{
				$('#loginMessagesuccess').html(json.msg).show();
			}
			$('#loginLoader').hide();
			$("#frm_login").find("[name=username],[name=password],[name=submit]").attr('disabled',false);
			if(!json.err) {
				window.location.href=$("#frm_login").find("[name=cur_url]").val();
			}
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			alert('Server Error')
			$('#loginLoader').hide();
			$("#frm_login").find("[name=username],[name=password],[name=submit]").attr('disabled',false);
		}
	});
}

/*
			function updateMe(txt){				
					var range = $(this).getSelection();					
					$(this).text($(this).text().substr(0, range.start) + "omar" + $(this).text().substr(range.end, $(this).text().length));				

			}
*/

			var start=0;
			var end	 =0;
			var code = 'sss';
			
			function updatePos(){
				var range = $(this).getSelection();	
				start	  = range.start;
				end		  = range.end;
			}
			
			function addIcon(icon){				
				code = icon;
				$('#txtcomment').mouseover(updateMe);
				$('#txtcomment').mouseover();
				$('#txtcomment').unbind('mouseover');
			}
			
							
			function updateMe(){
				var range = $(this).getSelection();	//alert(start);
				var textStart = (start > range.start) ? range.start : $(this).text().length;
				var textEnd = (end > range.end) ? range.end : 0;			
				
				$(this).text($(this).text().substr(0, textStart) + ' [icon]'+code+'[/icon] '+ $(this).text().substr(textEnd, $(this).text().length));	
				

				
				
				//alert(range.start);
				//$(this).text($(this).text().substr(0, range.start) + ' [icon]'+code+'[/icon] '+ $(this).text().substr(range.end, $(this).text().length));				

			}

/*
			function addIcon(icon){
				var code = $(icon).attr('title');
				var txtarea = document.getElementById('txtcomment');
				//JOSC_scrollToCursor(txtarea, 0);
				
				$('#txtcomment').insertAtCaret(' [icon]'+code+'[/icon] ');
				alert(code);
				return false;
				
				
				txtarea.focus();
				JOSC_pasteAtCursor(txtarea, ' [icon]'+code+'[/icon] ');
				JOSC_scrollToCursor(txtarea, 1);

			}
*/
			function JOSC_scrollToCursor(txtarea, action) {
			  if (is_ie) {
				if (action == 0) {
				  JOSC_scrollTopPos = txtarea.scrollTop;
				  JOSC_scrollLeftPos = txtarea.scrollLeft;
				} else {
				  txtarea.scrollTop = JOSC_scrollTopPos;
				  txtarea.scrollLeft = JOSC_scrollLeftPos;
				}
			  }
			}

			function JOSC_pasteAtCursor(txtarea, txtvalue) {
			  if (document.selection) {
				var sluss;
				txtarea.focus();
				sel = document.selection.createRange();
				sluss = sel.text.length;
				sel.text = txtvalue;
				if (txtvalue.length > 0) {
				  sel.moveStart('character', -txtvalue.length + sluss);
				}
			  } else if (txtarea.selectionStart || txtarea.selectionStart == '0') {
				var startPos = txtarea.selectionStart;
				var endPos = txtarea.selectionEnd;
				txtarea.value = txtarea.value.substring(0, startPos) + txtvalue + txtarea.value.substring(endPos, txtarea.value.length);
				txtarea.selectionStart = startPos + txtvalue.length;
				txtarea.selectionEnd = startPos + txtvalue.length;
			  } else {
				txtarea.value += txtvalue;
			  }
			}

			
			

			
function Sendtofriend(){
			
			$("#frm_sendtofriend").find("[name=friendMail],[name=submit]").attr('disabled',true);
			$('#sendToFriendDialogMessageFailure,#sendToFriendDialogMessagesuccess').hide();
			$('#sendToFriendDialogLoader').hide();
					$.ajax({
					url: "index.php?pg=sendtofriend&disable_rewrite=1",
					type:"POST",
					async: true,
					dataType:'json',
					data: {
						lang:g_lang_code,
						friendMail:$("#frm_sendtofriend").find("[name=friendMail]").val(),
						cur_url:$("#frm_sendtofriend").find("[name=cur_url]").val()
					},
					beforeSend: function(XMLHttpRequest) {
					},
					success: function(json){
						
								if(json.err) {
								$('#sendToFriendDialogMessageFailure').html(json.msg).show();
								}else{
									$('#sendToFriendDialogMessagesuccess').html(json.msg).show();
								}
								//alert('success') ;
								$('#sendToFriendDialogLoader').hide();
								$("#frm_sendtofriend").find("[name=friendMail],[name=submit]").attr('disabled',false);	
						
								if(!json.err) {
								window.location.href=$("#frm_sendtofriend").find("[name=cur_url]").val();
								}
						
					
					},
					error: function (XMLHttpRequest, textStatus, errorThrown) {
						alert('Server Error') ;
						$('#sendToFriendDialogLoader').hide();
						$("#frm_sendtofriend").find("[name=friendMail],[name=submit]").attr('disabled',false);
					}
				});
		}


function logout() {
	window.location.href = g_url_logout;
}

function bannerShowImage(id) {
	 window.location = bannerShowImageUrl+"?id="+id;//"index.php?pg=arenagallery" ;
}

function gallaryShowImage(id) {
	 window.location = gallaryShowImageUrl+"?id="+id;//"index.php?pg=wallpapergallery" ;
}


////////////////////////////////////////////////////////
function showgroup() {
		$("#group_dialog").dialog('open');
}

function addgroup() {
	$("#frm_group").find("[name=groupname],[name=submit]").attr('disabled',true);
	$('#groupMessageFailure,#groupMessagesuccess').hide();
	$('#groupLoader').show();
	$.ajax({
		url: "index.php?pg=championships/addgroup&disable_rewrite=1",
		type:"POST",
		async: true,
		dataType:'json',
		data: {
			plain:1,
			lang:g_lang_code,
			groupname:$("#frm_group").find("[name=groupname]").val(),
			id:$("#frm_group").find("[name=champion_id]").val()
			
		},
		beforeSend: function(XMLHttpRequest) {
		},
		success: function(json){
			if(json.err) {
				$('#groupMessageFailure').html(json.msg).show();
			}else{
				$('#groupMessagesuccess').html(json.msg).show();
			}
			$('#groupLoader').hide();
			$("#frm_group").find("[name=groupname],[name=submit]").attr('disabled',false);
			if(!json.err) {
				window.location.href=$("#frm_group").find("[name=cur_url]").val();
			}
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			alert('Server Error')
			$('#groupLoader').hide();
			$("#frm_group").find("[name=groupname],[name=submit]").attr('disabled',false);
		}
	});
}


//////////////////////////////////////////////////////////

// remove link background images since we're re-doing the hover interaction below
// (doing it this way retains the CSS default hover states for non-javascript-enabled browsers)
// we also want to only remove the image on non-selected nav items, so this is a bit more complicated
function cssNavigation(parent) {
	//only for setting current
	$("."+parent).children("li").each(function() {
		var current = parent+" current-" + ($(this).attr("class"));
		var parentClass = $("."+parent).attr("class");
		if (parentClass != current) {
			$(this).children("a").css({backgroundImage:"none"});
		}
	});
}
function cssTabNavigation(parent) {
	//only for setting current
	$("."+parent).children("li").each(function() {
		var current = parent+" current-" + ($(this).attr("class"));
		var parentClass = $("."+parent).attr("class");
		if (parentClass != current) {
			$(this).children("a").css({backgroundImage:"none"});
		}
	});
}
function attachNavEvents(parent, myClass) {
	$("."+parent + " ." + myClass).mouseover(function() {
		$(this).append('<div class="'+parent+'-' + myClass + '"></div>');
		$("div."+parent+"-" + myClass).css({display:"none"}).fadeIn(200);
	}).mouseout(function() {
		$("div."+parent+"-" + myClass).fadeOut(200, function() {
			$(this).remove();
		});
	}).mousedown(function() {
		$("div."+parent+"-" + myClass).attr("class", parent+"-" + myClass + "-click");
	}).mouseup(function() {
		$("div."+parent+"-" + myClass + "-click").attr("class", parent+"-" + myClass);
	});
}
function attachTabEvents(parent, myClass) {
	$("."+parent + " ." + myClass).click(function() {
		$("."+parent).children("li").each(function() {
			var thisClass = $(this).attr("class");
			//$("."+parent).attr('class',parent+' current-'+thisClass);
			if( myClass == $(this).attr("class") ) {
				$(this).append('<div class="'+parent+'-' + thisClass + '-click"></div>');
				$('#'+parent+'-'+thisClass+'-content').show();
				$('#'+parent+'-'+thisClass+'-content .tabFooter').css("zIndex","-10000");
			}else{
				//$(this).attr("class", thisClass);
				$("div."+parent+"-" + thisClass+'-click').remove();
				$('#'+parent+'-'+thisClass+'-content').hide();
			}
		});
		//alert(parent);
		//alert($("."+parent+" .has(ul)"));
	});
}


function galleryThumbEffect() {
	$(".galleryImg").mouseenter(function(){
		$("img:first",this).fadeTo(50, 1);
	}).mouseleave(function(){
		$("img:first",this).fadeTo(50, 0.70);
	});
}
function galleryCategoriesThumbEffect() {
	$(".galleryCategoryImg").mouseenter(function(){
		$(this).toggleClass('galleryCategoryImgHover');
	}).mouseleave(function(){
		$(this).toggleClass('galleryCategoryImgHover');
	});

	$(".galleryCategoryImgBack").mouseenter(function(){
		$(this).toggleClass('galleryCategoryImgBackHover');
	}).mouseleave(function(){
		$(this).toggleClass('galleryCategoryImgBackHover');
	});

}


function rating(div, url, idAttr){
	$(div).live("click", function(){											// div = "div[class*='starActive']"
		var thisStar = $(this);
		if(thisStar.parent().attr('enablerate')==0) return;
		var cls = $(this).attr('class');
		var rate = (parseInt(cls.substr(10,1))).toString();
		thisStar.parent().parent().find('.thanksForRating').show();
		thisStar.parent().attr('enablerate',0);
		$.ajax({
			url			: url,													// url = "index.php?pg=articles/article&plain=1&disable_rewrite=1"
			type		: "POST",
			async		: true,
			dataType	: "json",
			data		: {
							mode:'rating',
							lang:g_lang_code,
							id:$(this).parent().attr(idAttr),					// idAttr = 'article'
							rate:rate
							},
							
			beforeSend	: function(XMLHttpRequest) {
							},
			success: function(json){
				thisStar.parent().parent().find('.thanksForRating').html(json.msg);
				var originalrate = 'starsRating'+json.newRate;
				thisStar.parent().attr('originalrate',originalrate).attr('class',originalrate);
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				thisStar.parent().parent().find('.thanksForRating').hide();
				alert('Communication Error');
			}
		});
	}).live("mouseover",function() {
		if($(this).parent().attr('enablerate')==1) {
			var cls = $(this).attr('class');
			var className = 'starsRating'+(parseInt(cls.substr(10,1))).toString();
			$(this).parent().attr('class',className);
		}
	}).live('mouseout',function () {
		if($(this).parent().attr('enablerate')==1) {
			var originalrate = $(this).parent().attr('originalrate');
			$(this).parent().attr('class',originalrate);
		}
	});
	
}


function display_comments(id,key){
						$.ajax({
							url: commentsUrl,//"index.php?pg=comments/comments&plain=1",
							type:"GET",
							async: true,
								data: {
									   id:id,
									   key:key
									  },
							beforeSend: function (XMLHttpRequest) {		},
							success: function(html){
								$("#divComments").slideUp('slow',function(){
									$(this).html(html);
									$(this).slideDown('slow');							
								});
							},
							error: function (XMLHttpRequest, textStatus, errorThrown) {		}
						});	
}



/***********************	VOTES	**********************/
															
							var vote = function(id){

								$("#poll_form_"+id).submit(												   
									formProcess
								); // setup the submit handler this.formProcess
							  
							  	if($("#poll_form_"+id+" input[id='resultsButton']").length > 0){
									$("#poll_form_"+id+" input[id='resultsButton']").click(function(){
										var vote_id	= id;
										var action = $("#poll_form_"+vote_id).attr('action');	
										var opt_id = $.cookie('vote_'+vote_id)>0 ? $.cookie('vote_'+vote_id) : 0;
										var form_container = $("#poll_form_"+vote_id).parent();
										var data = eval($("#poll_form_"+vote_id +" input[name='vote_values']").val().replace("&quot;",'')); 
	
										form_container.fadeOut("fast",function(){
											$(this).empty();
											loadResults(0, vote_id, opt_id, data, form_container);	
										});
										return false;
									});
								}
								
							  	if ($("#poll-results-"+id).length > 0 ) {
							    	animateResults(id);
							  	}
							  	/*
							  	if ($.cookie('vote_'+id)) {
									var vote_id	= id;
									var action = $("#poll_form_"+vote_id).attr('action');	
									var opt_id = $.cookie('vote_'+vote_id);
									var form_container = $("#poll_form_"+vote_id).parent();
									var data = eval($("#poll_form_"+vote_id +" input[name='vote_values']").val().replace("&quot;",'')); 

									form_container.fadeOut("fast",function(){
										$(this).empty();
										loadResults(0, vote_id, opt_id, data, form_container);	
									});
									
							  	}
								*/
								function formProcess(event){
									event.preventDefault();
									var vote_id	= id;
									var action = $("#poll_form_"+vote_id).attr('action');	
									var opt_id;
									if($("#poll_form_"+vote_id+" input[@name='poll_opt']:checked").length > 0){
										opt_id= $("#poll_form_"+vote_id+" input[@name='poll_opt']:checked").attr("value").replace("opt",'');
									}
									var form_container = $("#poll_form_"+vote_id).parent();
									var data = eval($("#poll_form_"+vote_id +" input[name='vote_values']").val().replace("&quot;",'')); 
									

									$("#poll_form_"+vote_id).parent().fadeOut("slow",function(){
										$(this).empty();
										
										$.getJSON(action+"?vote_id="+vote_id+"&opt_id="+opt_id,	function(flag){	loadResults(flag, vote_id, opt_id, data, form_container);
							  } );									
															    
										$.cookie('vote_'+vote_id, opt_id, {expires: 60*1000});	// 365
									});
								}	
								
								animateResults = function(vote_id){
									  $("#poll-results-"+vote_id+" div").each(function(){
										  var percentage = $(this).next().text();
										  $(this).css({width: "0%"}).animate({width: percentage}, 'slow');
									  });
								}
							
							
								loadResults = function (flag, vote_id, opt_id, data, form_container) {
									var total_votes = 0;
									var percent;
									
									$.each(data,function(i,item){
										if(opt_id == item.id && flag == 1)data[i].value = parseInt(data[i].value)+1;
										total_votes+= parseInt(item.value);
									});

									var results_html = "<div class='poll-results' id='poll-results-"+vote_id+"'><h4><br />"+poll_results_address+"</h4>\n<dl class='graph'>\n";
									var divColor = '';
									
									$.each(data,function(i,item){
										percent = Math.round((parseInt(item.value)/parseInt(total_votes ? total_votes : 1))*100);									
										
										if (item.id !== opt_id) divColor = '660000'; else divColor = '0066cc';
										
										results_html = results_html+"<dt class='bar-title'>"+item.title+"</dt><dd class='bar-container'><div id='bar"+item.id+"' style='width:0%;background-color:#"+divColor+";'>&nbsp;</div><span>"+percent+"%</span></dd>\n";						
									});
									
									results_html = results_html+"</dl><p style='clear:both;text-align:right;'>"+total_votes_address+": "+total_votes+"</p><hr /></div>\n";
									  
									form_container.append(results_html).fadeIn("slow",function(){
										animateResults(vote_id);
									});
								}
										
									
							}
							
/**********************************************/
	function sendToFriend(){
		$('#sendToFriendDialog').dialog('open');
	}
	
	function addShareToolbox(divId){
	
		$("#"+divId).append(
			'<div class="addthis_toolbox addthis_default_style" style="float:left; margin-top:-10px;">'
				+'<a class="addthis_button_facebook"></a>'
				+'<a class="addthis_button_email"></a>'
				+'<a class="addthis_button_favorites"></a>'
				+'<a class="addthis_button_print"></a>'
				+'<span class="addthis_separator">|</span>'
				+'<a href="http://www.addthis.com/bookmark.php?v=250&amp;pub=xa-4af94c134e77d096" class="addthis_button_expanded">More</a>'
			+'</div>'
			+'<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pub=xa-4af94c134e77d096"></script>'
		
		);

	}
	
	function printPartOfPage(div){

		var html=$('head').html();//+$(div).html();
		
		if($(div).length > 0){
			html+="<div>";
			$(div).each(function(index, element){
				html+=$(element).html();
				//alert($(element).html());
			});
			html+="</div>";
		}else{
			html+=$(div).html();
		}
		
		if($("iframe [name='print_frame']").length < 1 ){
			/*
			var iframe = document.createElement("iframe");
			$(iframe).attr("name","print_frame");
			$(iframe).attr("id","print_frame");
			*/
			
			$(document.body).append('<iframe id="print_frame" name="print_frame"></iframe>');//$(iframe));
			/*
			$('#print_frame').attr('src','#');
			$('iframe#print_frame').ready(function(){
				$(this).html(html);
				window.print();
			});
			*/
		}
		window.frames["print_frame"].document.body.innerHTML=$('head').html()+$(div).html();
		window.frames["print_frame"].window.print();
		//$('#print_frame').remove();
		//}	
			/*alert($('#print_frame'));
			$('#print_frame').document.body.html($('head').html()+$(div).html());/*
		window.frames["print_frame"].document.body.innerHTML=$('head').html()+$(div).html();
		window.frames["print_frame"].window.print();*/
	}
			
/**********************************************/
	function reloadGalleryWallpaper(which){
		var gallary_item = new SWFObject(g_smarty_templatepath+"/images/swf/Gallary.swf", "gallary_item", "310", "255", "9",'' );
		gallary_item.addParam("wmode", "transparent");
		gallary_item.addVariable("xmlfile", eval("g_footer_xmlfile"+which));
		gallary_item.write("gallary_container_"+which);
	}
	
/**********************************************/
$(document).ready(function(){
	$("#dialog").dialog({ modal: true ,resizable: false ,autoOpen: false });
	$("#group_dialog").dialog({ modal: false ,resizable: true ,autoOpen: false, position: 'center', width: 250});
	$("#sendToFriendDialog").dialog({ modal: true ,resizable: false ,autoOpen: false });

	$(".newsItemContainer").mouseenter(function(){
		$(this).toggleClass('newsItemContainerActive');
	}).mouseleave(function(){
		$(this).toggleClass('newsItemContainerActive');
	}).click(function(){
		window.location.href = $(this).attr('url');
	});



	//News Marqueue
	$jScroller.cache.init = true;
	$jScroller.config.refresh = 100;
	$jScroller.add("#box1_container","#box1_content","right",2,false);
	$jScroller.start();

/*
	//Article Rating
	if(g_pg =='articles/article') {

		$("div[class*='starActive']").live("click", function(){
			var thisStar = $(this);
			if(thisStar.parent().attr('enablerate')==0) return;
			var cls = $(this).attr('class');
			var rate = (parseInt(cls.substr(10,1))).toString();
			thisStar.parent().parent().find('.thanksForRating').show();
			thisStar.parent().attr('enablerate',0);
			$.ajax({
				url: "index.php?pg=articles/article&plain=1&disable_rewrite=1",
				type:"POST",
				async: true,
				dataType: "json",
				data: {
					mode:'rating',
					lang:g_lang_code,
					id:$(this).parent().attr('article'),
					rate:rate
				},
				beforeSend: function(XMLHttpRequest) {
				},
				success: function(json){
					thisStar.parent().parent().find('.thanksForRating').html(json.msg);
					var originalrate = 'starsRating'+json.newRate;
					thisStar.parent().attr('originalrate',originalrate).attr('class',originalrate);
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					thisStar.parent().parent().find('.thanksForRating').hide();
					alert('Communication Error')
				}
			});
		}).live("mouseover",function() {
			if($(this).parent().attr('enablerate')==1) {
				var cls = $(this).attr('class');
				var className = 'starsRating'+(parseInt(cls.substr(10,1))).toString();
				$(this).parent().attr('class',className);
			}
		}).live('mouseout',function () {
			if($(this).parent().attr('enablerate')==1) {
				var originalrate = $(this).parent().attr('originalrate');
				$(this).parent().attr('class',originalrate);
			}
		});
	}


	//Arena Gallery Rating
	if(g_pg =='arenagallery') {
		$("div[class*='starActive']").live("click", function(){
			var thisStar = $(this);
			if(thisStar.parent().attr('enablerate')==0) return;
			var cls = $(this).attr('class');
			var rate = (parseInt(cls.substr(10,1))).toString();
			thisStar.parent().parent().find('.thanksForRating').show();
			thisStar.parent().attr('enablerate',0);
			$.ajax({
				url: "index.php?pg=arenagallery&plain=1&disable_rewrite=1",
				type:"POST",
				async: true,
				dataType: "json",
				data: {
					mode:'rating',
					lang:g_lang_code,
					id:$(this).parent().attr('galleryimg'),
					rate:rate
				},
				beforeSend: function(XMLHttpRequest) {
				},
				success: function(json){
					thisStar.parent().parent().find('.thanksForRating').html(json.msg);
					var originalrate = 'starsRating'+json.newRate;
					thisStar.parent().attr('originalrate',originalrate).attr('class',originalrate);
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					thisStar.parent().parent().find('.thanksForRating').hide();
					alert('Communication Error')
				}
			});
		}).live("mouseover",function() {
			if($(this).parent().attr('enablerate')==1) {
				var cls = $(this).attr('class');
				var className = 'starsRating'+(parseInt(cls.substr(10,1))).toString();
				$(this).parent().attr('class',className);
			}
		}).live('mouseout',function () {
			if($(this).parent().attr('enablerate')==1) {
				var originalrate = $(this).parent().attr('originalrate');
				$(this).parent().attr('class',originalrate);
			}
		});
	}



	//Wallpapergallery Gallery Rating
	if(g_pg =='wallpapergallery') {
		$("div[class*='starActive']").live("click", function(){
			var thisStar = $(this);
			if(thisStar.parent().attr('enablerate')==0) return;
			var cls = $(this).attr('class');
			var rate = (parseInt(cls.substr(10,1))).toString();
			thisStar.parent().parent().find('.thanksForRating').show();
			thisStar.parent().attr('enablerate',0);
			$.ajax({
				url: "index.php?pg=wallpapergallery&plain=1&disable_rewrite=1",
				type:"POST",
				async: true,
				dataType: "json",
				data: {
					mode:'rating',
					lang:g_lang_code,
					id:$(this).parent().attr('galleryimg'),
					rate:rate
				},
				beforeSend: function(XMLHttpRequest) {
				},
				success: function(json){
					thisStar.parent().parent().find('.thanksForRating').html(json.msg);
					var originalrate = 'starsRating'+json.newRate;
					thisStar.parent().attr('originalrate',originalrate).attr('class',originalrate);
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					thisStar.parent().parent().find('.thanksForRating').hide();
					alert('Communication Error')
				}
			});
		}).live("mouseover",function() {
			if($(this).parent().attr('enablerate')==1) {
				var cls = $(this).attr('class');
				var className = 'starsRating'+(parseInt(cls.substr(10,1))).toString();
				$(this).parent().attr('class',className);
			}
		}).live('mouseout',function () {
			if($(this).parent().attr('enablerate')==1) {
				var originalrate = $(this).parent().attr('originalrate');
				$(this).parent().attr('class',originalrate);
			}
		});
	}

*/
	/*
	// create events for each nav item
	cssNavigation("nav1");
	attachNavEvents("nav1", "favorites");
	attachNavEvents("nav1", "registration");
	attachNavEvents("nav1", "login");
	attachNavEvents("nav1", "logout");
	/*
	cssNavigation("nav2");
	attachNavEvents("nav2", "team");
	attachNavEvents("nav2", "votes");
	attachNavEvents("nav2", "proleagues");
	attachNavEvents("nav2", "expectation");
	attachNavEvents("nav2", "gallery");
	attachNavEvents("nav2", "multimedia");
	attachNavEvents("nav2", "articles");
	attachNavEvents("nav2", "prof");
	attachNavEvents("nav2", "news");
	attachNavEvents("nav2", "home");

	/*cssTabNavigation("nav7");
	attachTabEvents("nav7", "tab1");
	attachTabEvents("nav7", "tab2");
	$('.nav7 .tab1').click();

	cssTabNavigation("nav7_1");
	attachTabEvents("nav7_1", "tab1_1");
	attachTabEvents("nav7_1", "tab1_2");
	attachTabEvents("nav7_1", "tab1_3");
	$('.nav7_1 .tab1_1').click();
	*/

	cssTabNavigation("nav7");
	attachTabEvents("nav7", "tab1");
	attachTabEvents("nav7", "tab2");
	$('.nav7 .tab1').click(function(){
		$('.nav7_1_container').hide();
	});
	$('.nav7 .tab2').click(function(){
		$('.nav7_1_container').show();
	});
	$('.nav7 .tab2').click();

	cssTabNavigation("nav7_1");
	attachTabEvents("nav7_1", "tab1");
	attachTabEvents("nav7_1", "tab2");
	attachTabEvents("nav7_1", "tab3");
	$('.nav7_1 .tab3').click();
/*
	cssTabNavigation("nav8");
	attachTabEvents("nav8", "tab1");
	attachTabEvents("nav8", "tab2");
	attachTabEvents("nav8", "tab3");
	attachTabEvents("nav8", "tab4");
	attachTabEvents("nav8", "tab5");
	$('.nav8 .tab5').click();
*/
	cssTabNavigation("nav9");
	attachTabEvents("nav9", "tab1");
	attachTabEvents("nav9", "tab2");
	$('.nav9 .tab2').click();





	cssTabNavigation("navbackgrounds");
	attachTabEvents("navbackgrounds", "tab1");
	attachTabEvents("navbackgrounds", "tab2");
	$('.navbackgrounds .tab1').click();
	
	$('li').each(function(index,element){
		$(this).click(function(){	  pageTracker._trackPageview("/ar/news-test1.html"); });
	});
	
	//$('div.paging-container').children('a').each(function(index,element){
	$('a').each(function(index,element){
		$(this).click(function(){	  pageTracker._trackPageview("/counter&pages"); });
	});	
	
});
