// JavaScript Document
var track = 0;

$(document).ready(function(){//
						   
			$("#youtube_dialog").dialog({autoOpen: false,height: 410,width: 470,resizable: false});

			$("#avg").children().not(":input").hide();
			$("#rat").children().not("select, #messages").hide();
			
			$("#avg").stars();
			
			//alert($.cookie("star_voting["+$("#item_id").val()+"]"));
			if($.cookie("star_voting["+$("#item_id").val()+"]")>0){
				//$("#rat").data("stars").options.checked = $.cookie("star_voting["+$("#item_id").val()+"]");
				//$("#rat").stars({inputType: "select",disabled:true});
				$("#rat").hide();
				
															}else{
			$("#rat").stars({
				inputType: "select",
				cancelShow: false,
				captionEl: $("#caption"),
				callback: function(ui, type, value){
					ui.disable();
					$("#messages").text("Αποθήκευση...").stop().css("opacity", 1).fadeIn(30);
					
					var my_id = $("#item_id").val();
					$.post("json/static_articles_star-voting.php", {rate: value,id:my_id}, function(db){
							$("#avg").stars("select", Math.round(db.avg));
							
							$("#all_votes").text(db.votes);
							$("#all_avg").text(db.avg);
							
							$("#messages").text("Καταχωρήθηκε η βαθμολογία:  (" + value + "). Ευχαριστούμε!").stop().css("opacity", 1).fadeIn(30);
							setTimeout(function(){
								$("#messages").fadeOut(1000, function(){  ui.enable(); $("#rat").hide(); 
																		
						          var date = new Date();
								  date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000));
								  $.cookie("star_voting["+my_id+"]", value, { path: '/', expires: date });
																		})
							}, 2000);
					}, "json");
				}
			});
																
																	}
							   


			$("#rat").stars("selectID", -1);

			$('<div id="messages"/>').appendTo("#rat");


		$("#youtube_over").click(function(){
			var title = $(this).attr("rel_title");
			//$("#youtube_dialog").attr("title",title);
			$("#youtube_dialog").dialog('option', 'title', title);
			
			var id = $(this).attr("rel_id");
			$("#youtube_dialog").dialog('open').load('system/static_articles_youtube.php?id='+id);			 								 
											 });
		
		
		
		 $('a[rel=lightbox]').lightBox();


	$("#youtube_over_hover").hover(function(){$('#youtube_hover_over').fadeOut('fast');},function(){$('#youtube_hover_over').fadeIn('slow');});
	
});
