$(function() {
	setupMenu();
	// setup rating functionality
	$(".starrate").bind('click',function(){ 
		// page: will be {$cur_page.id}
		runFunction("ratePage", {page: $("#rater").attr("title"), rate: $(this).attr("id")}, function(response) {
			perc = response.your_rate*20;
			$('#current-rating').attr("style","width:"+perc+"%; background-position: left bottom;");
			$('#avg_rate').html(response.avg_rate+"/5 average rating");
			$('#rater-init').unbind('mouseout');
			$('#rater').unbind('mouseout');
		});
		return false;
	});
	$('#rater-init').bind('mouseover',function() {
		$('#rater').show();					  
	});
	// hide this from IE6
	if (!document.all || window.opera || window.XMLHttpRequest) {
		$('#rater-init').bind('mouseout',function() {
			$('#rater').hide();
		});
		$('#rater').bind('mouseover',function() {
			$('#rater').show(); 
		});
		$('#rater').bind('mouseout',function() {
			$('#rater').hide();
		});
	}
});
function toggleSelected(el){
	alert(el);
}

function clearFooter(el){
	if(el.value == 'Enter your email'){
		el.value = '';	
	}
}

/******************************/
function setupMenu() {
	$('div#menu ul li').hover(function() {
		$('ul#' + $(this).attr('id') + '-menu').show();
	}, function() {
		$('ul#' + $(this).attr('id') + '-menu').hide();
	});
	$('div#spmenu ul li').hover(function() {
		$('ul#' + $(this).attr('id') + '-menu').show();
	}, function() {
		$('ul#' + $(this).attr('id') + '-menu').hide();
	});
	$('div#submenus ul').hover(function() { 
		$(this).show(); 
		thisid = $(this).attr('id');
		parentid = thisid.substring(0,(thisid.length-5));
		$("#"+parentid+" a").addClass('selected');
	}, function() { 
		$(this).hide(); 
		$("#"+parentid+" a").removeClass('selected');
	});
	$('div#submenus ul ul').hover(function() { $(this).show(); }, function() { $(this).show(); });	
}
function goTo(url) {
	window.location = url;
}
function closeTB(){
	tb_remove();	
}
function runFunction(name, data, callback){
	callback = callback || function() {};
	$.ajax({url:'modules/ajax.php?'+name , dataType:"json", type: "POST", data:data, success:function(response) {
		if (response.status == 1){	
			if(response.success_msg != '') {
				alertIt('success',response.success_msg);
			}
			callback(response);
		}else{
			if(response.error_msg != '') {
				alertIt('error',response.error_msg);
			}
		}
	}});
}