$('document').ready(function(){
	$(function(){
	
		// Tabs
		$('#lasts').tabs({
			fx: { opacity: 'toggle' }
		});
		$('#lasts').css({'display':'block'});
		$('#loading').css({'display':'none'});
		$(function(){
			 lasts = setInterval("roll_lasts()",10000);
		});
	});

});

document.write('<div id="tip"></div>');

function roll_lasts(){
	var selected = $('#lasts').tabs('option', 'selected');
	if(selected == 5){
		$('#lasts').tabs('option', 'selected',0);
	} else {
		$('#lasts').tabs('option', 'selected', (selected+1));
	}
	$("#tip").hide("slow");

}

function tip(img,e){
	$('#tip').fadeIn('fast').html('<img src="'+img+'" alt="pic" />');    
     $(this).bind("mousemove",function(e){
           var y = e.pageY-30+"px";
           var x = e.pageX+25+"px";
           $('#tip').css({'left':x ,'top': y});
     });

}
function hidetip(){
     $('#tip').css({'display':'none'});
     $(this).unbind("mousemove");
}		
function del(url) {
	var check = confirm("Сигурни ли сте че искате да изтриете това?");
	if(check == true) {
		window.location=url;
	} 
}

function reportContent(type,id){
	var descr = prompt("Опишете с няколко думи проблема:","");
	if(descr){
		$.post("report.php", {type: type, id: id,descr: descr},
		function(data){
			alert(data);
		});
	}
}
function changepage(url) {
	var page =  document.forms.page.pages.value;
	window.location = url+page;
}

function showComment(){
	$('#comments .add').slideToggle('fast');
	document.forms.add.comment.disabled = false;
	document.forms.add.send.disabled = false;
	document.forms.add.comment.value = "";
}
function addComment(form,type,id){
var comment = form.comment.value;
form.comment.disabled = true;
form.send.disabled = true;
if(comment==""){
	alert("Напишете коментар преди да изпратите към сайта!");
	form.comment.disabled = false;
	form.send.disabled = false;
} else {
		$.post("comments.php", { act: 'add', type: type, id: id ,comm: comment},
		function(data){
			$('.list').html(data);
			});
}
 $("#comments .add").ajaxSuccess(function(evt, request, settings){
   	document.forms.add.comment.disabled = false;
	document.forms.add.comment.value = "";
	document.forms.add.send.disabled = false;
	$(this).slideUp('slow');
 });

	
}

function updateComment(form,cid,type,id,page){
var comment = form.comment.value;
form.comment.disabled = true;
form.send.disabled = true;
	if(comment==""){
		alert("Напишете коментар преди да изпратите към сайта!");
		form.comment.disabled = false;
		form.send.disabled = false;
	} else {
		$.post("comments.php", { act: 'update',cid: cid, type: type, id: id ,comm: comment, p: page},
			function(data){
				$('.list').html(data);
				});
	}

}
function getComment(type,id,page){
	$('.list').fadeTo('fast',0.1,function(){
			$.post("comments.php", { type: type, id: id ,p: page},
				function(data){
					$('.list').html(data);
				});
	}).fadeTo('fast',1);
}

function delComment(elm,cid,type,id,page){
	var get = confirm("Искате ли да изтриете мнението?");
	if(get){
		$(elm).parent().slideUp('slow',function(){
		$.post("comments.php", {act:'del', cid: cid, type: type, id: id ,p: page},
		function(data){
			$('.list').html(data);
		});
		});
	}
}
function editComment(cid,type,id,page){
		$.post("comments.php", {act:'edit', cid: cid, type: type, id: id ,p: page},
		function(data){
			$('.list').html(data);
		});

}


function over_rate(rate,type,id){
	for(var i = 1;i<=rate;i++){
		$('.'+i).addClass("hi");	
	}

	$('.'+rate).bind("click",function(){
			$("#rating").fadeTo('slow',0.5,function(){
			$.post("rating.php",{rate: rate,type:type,id: id},
				function(data){
					$('#rating').html(data);
				});
			});
	});
	$("#rating").ajaxSuccess(function(evt, request, settings){
		 $("#rating").fadeTo('slow',1);

	});
}

function out_rate(star){
	$('.star').removeClass("hi");
	$('.star_off').removeClass("hi");
	$('.'+star).unbind("click");
}

function switch_news(num){
	clearInterval(change);
	if(num == 4)
		num = 0;
	else
		num ++;
	get_news(num);
}	
function get_news(num){
	clearInterval(change);
	$('#last_news .img').fadeTo("slow",0.5, function(){
			$.post("last_news.php",{num: num},
	function(data){
		$('#last_news').html(data);
		$('#last_news .img').css({"opacity":"0.5"});
		$('#last_news .img').fadeTo("slow",1);
	});
	});
	change = setInterval("switch_news("+num+")",5000);

	
}

function fav(type,id,act){
			$("#favourite_add_rem").fadeTo('slow',0.5,function(){
				$.post("favourite.php",{type:type,id: id,act: act},
				function(data){
					$('#favourite_add_rem').html(data);
				});
			});
	$("#favourite_add_rem").ajaxSuccess(function(evt, request, settings){
		$("#favourite_add_rem").fadeTo('slow',1);
	});
}

function addGreet(type,id){
$.post("addgreet.php",{type:type,id: id},
				function(data){
						$('#greet').html(data);
				});
}
var navDef = "4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
if(navigator.appVersion == navDef){
	document.write("<div style=\"width: 1000px;margin: 0 auto;border:none;\"><iframe style=\"overflow:none;\" src =\"ie.html\" width=\"100%\" height=\"100\"></iframe></div>");
}