$(document).ready(function(){
	
	$('ul.sf-menu').superfish({ 
            hoverClass:    'sfHover',          // the class applied to hovered list items 
			delay:         800,                // the delay in milliseconds that the mouse can remain outside a submenu without it closing 
			animation:     {opacity:'show'},   // an object equivalent to first parameter of jQuery’s .animate() method 
			speed:         'fast',           // speed of the animation. Equivalent to second parameter of jQuery’s .animate() method 
			autoArrows:    false,               // if true, arrow mark-up generated automatically = cleaner source code at expense of initialisation performance 
			dropShadows:   false,               // completely disable drop shadows by setting this to false 
			disableHI:     false              // set to true to disable hoverIntent detection 
        }); 
	
	/*$('#family-navigation').menu({
			mode: 'static',
			type: 'flyout',
			nextMenuClass: 'ui-arrow-right-default',
			//selectCategories: true,
			choose: function(event, ui) {
				go_to (self, $(item).attr('href'));
			}
		});*/
	
	$(".uiAccordion").accordion();
	
	$(".uiTabs").tabs();
	
	$(".uiDialog").dialog({
           autoOpen: false,
           modal: true,
           height: 500,
           width: 800
       });
	
	$(".uiInput").customInput();
	$(".uiSelectMenu").selectmenu();
	
	$("#productAddMenuBt").click( function() {
		if ($("#productAddMenuBt > .ui-icon").hasClass('ui-icon-plusthick')) {
			$("#productAddMenu").slideDown();
			$("#productAddMenuBt > .ui-icon").removeClass('ui-icon-plusthick');
			$("#productAddMenuBt > .ui-icon").addClass('ui-icon-closethick');
		} else {
			$("#productAddMenu").slideUp();
			$("#productAddMenuBt > .ui-icon").addClass('ui-icon-plusthick');
			$("#productAddMenuBt > .ui-icon").removeClass('ui-icon-closethick');
		}
	});		
	$(".ceebox").ceebox({videoWidth: 853, videoHeight: 505, htmlWidth: 853, htmlHeight:505, htmlRatio:"16:9", imageWidth: 960, imageHeight: 550});
	
	
	$("#avg").children().not(":input").hide();
	$(".avg-stars").children().not(":input").hide();
	$("#rat").children().not("select, #messages").hide();
	$("#avg").stars();
	$(".avg-stars").stars();
	$("#rat").stars({
		inputType: "select",
		cancelShow: false,
		captionEl: $("#caption"),
		callback: function(ui, type, value)
		{
			ui.disable();
			$("#messages").text("Aguarde...").stop().css("opacity", 1).fadeIn(30);
			$.post("http://www.inforpascoa.pt/action/vote", {rate: value, product_id: $("#rate_product_id").val() }, function(db)
			{
					$("#avg").stars("select", Math.round(db.avg));
					$("#all_votes").text(db.votes);
					$("#all_avg").text(db.avg);
					$("#messages").text("O seu voto (" + value + ") foi guardado. Obrigado!").stop().css("opacity", 1).fadeIn(30);
					setTimeout(function(){ $("#messages").fadeOut(1000, function(){ui.enable()}) }, 2000);
				}, "json");
			}
		});
		$("#rat").stars("selectID", -1);
		$('<div id="messages"/>').appendTo("#rat");
});

function go_to (target, href) { try { target.location = href; } catch (e) { } }

function uiDialog(url, title, width, height) {
	if (width > 0)
		$("#uiDialog").dialog('option', 'width', width);
	if (height > 0)
		$("#uiDialog").dialog('option', 'height', height);
	$("#uiDialog").dialog('option', 'title', title);
	$("#uiDialog").html('<div id="uiDialogLoading"></div><iframe id="uiDialogFrame" width="100%" height="100%" marginWidth="0" marginHeight="0" frameBorder="0" scrolling="auto" />');
   	$("#uiDialogFrame").attr("src", url);
	$("#uiDialog").dialog('open');
   	return false;	
}

