jQuery.noConflict();

function addMega(){
	jQuery(this).addClass("hovering");
	jQuery(this).children("h2").addClass("hover");
}

function removeMega(){
	jQuery(this).removeClass("hovering");
	jQuery(this).children("h2").removeClass("hover");
}
/* Plugin to make variable height divs equal heights */
jQuery.fn.sameHeights = function() {

jQuery(this).each(function(){
var tallest = 0;

jQuery(this).children().each(function(i){
if (tallest < jQuery(this).height()) { tallest = jQuery(this).height(); }
});
jQuery(this).children().css({'height': tallest});
});
return this;
};



function tagCloudExternalInterfaceHandler(text){
	
	if(jQuery(document).ready(function() {
		if(jQuery("#mTagcloud .popup_" + text).length > 0) {
			jQuery.fn.colorbox({
				width: "770px",
				inline: true,
				href: "#mTagcloud .popup_" + text
			});	
		}
	}));
	
}

jQuery(document).ready(function() {
	
    var megaConfig = {
         interval: 0,
         sensitivity: 4,
         over: addMega,
         timeout: 200,
         out: removeMega
    };
	
	 

    jQuery("#navmenu li.mega").hoverIntent(megaConfig);
	
	jQuery("#navmenu li").hover(
	  function () {
		jQuery(this).siblings().children("h2").addClass("inactive");
	  }, 
	  function () {
		jQuery(this).siblings().children("h2").removeClass("inactive");
	  }
	);
	
	jQuery("li.mFrontFocusBox").hover(
	  function () {
		jQuery(this).addClass("hideImage");
	  }, 
	  function () {
		jQuery(this).removeClass("hideImage");
	  }
	);
	
	
	
	jQuery('.target').live('click',function(e){
		if(e.button===0){
			var $link=jQuery(this).find('a:last');
			if($link.length>0){
				var href=$link.attr('href');
				if(href){
					if($link.attr('target')==='_blank'){
						window.open(href);
					}
					else{
						document.location=href;
					}
				}
			}
		}
	});

	//Popup printbutton
	jQuery("#udskrivPrint").click(function() 
	{
		jQuery(".printPopup").stop(true, true).animate({opacity: "show"}, "slow");
		jQuery("#udskrivPrint").hide();
		jQuery(".annuller").show();
	});

	jQuery(".annuller").click(function() 
	{
		jQuery(".printPopup").stop(true, true).animate({opacity: "hide"}, "slow");
		jQuery(".annuller").hide();
		jQuery("#udskrivPrint").show();
		jQuery("#printButton").css('background', 'red');
	});
	
	jQuery("#printCheckbox").click(function()
	{
		var var_checkbox = jQuery("#printCheckbox").attr("checked")?1:0;
		if (var_checkbox == 0) {
			jQuery(".printImage img").hide();
			jQuery(".wideCol img").addClass('hideImg');
			jQuery(".printImage").addClass('printImage02');
		}
		else {
			jQuery(".printImage img").show();
			jQuery(".wideCol img").removeClass('hideImg');
			jQuery(".printImage").removeClass('printImage02');
		}
		
	});
	
	//Printing the recipe
	jQuery("#popupPrintButton").click(function() {
		window.print(); 
	});
	
	//Ie8 hover fix
	jQuery(".restaurant p").mouseover(function() {
        jQuery(this).css('backgroundColor', '#1a1a1a');
    })
	.mouseout(function() {
            jQuery(this).css('backgroundColor', 'transparent');
        });
		
	
	
	//Inputfelter, som skal cleares på focus tilføjes til følgende selector
    jQuery("#commentForm input, #commentForm textarea").each( function () {
        var $this = jQuery(this),
			origTxt = $this.val();
			origColor = $this.css("color");
			
		$this.css("color", "#888888");
		
        $this.bind("focus",  function() {
			$this.css("color", origColor);
            if($this.val() == origTxt) {
                $this.val("");
            }
        })
        .bind("blur", function() {
			
            if($this.val() == "") {
                $this.val(origTxt);
            }
			if($this.val() == origTxt) {
              	$this.css("color", "#888888");
            }
        });
     });
	
	//Tagcloud - fallback item link texts must match exactly the classname of a-tags in .popups - ie: popup_[NAMEOFLINKTEXT]
	if(jQuery("#mTagcloud").length > 0) 
	{
		
		/* HTML fallback popup binds */
		jQuery("#tagcloudAltContent").children("a").each(function() {
			
			jQuery(this).click( function(){
				if(jQuery("#mTagcloud .popup_" + jQuery(this).text()).length > 0) {
					jQuery.fn.colorbox({
						width: "770px",
						inline: true,
						href: "#mTagcloud .popup_" + jQuery(this).text()
					});	
				}
			});
		});	
		
		var flashvars = null;
		var params = {
			menu: "false",
			scale: "noScale",
			allowFullscreen: "true",
			allowScriptAccess: "sameDomain",
			bgcolor: "#FFFFFF",
			wmode: "opaque"
		};
		var attributes = {
			id:"mTagcloudObject"
		};
		
		swfobject.embedSWF("/flash/sushi_tagcloud.swf", "tagcloudAltContent", "301", "295", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
	}
	
	jQuery('.pageContainer1').sameHeights();
	
	
	
	jQuery.getScript('http://www.youtube.com/player_api');

		loadYouTubePlayer = function(playerID) {
		  the_player = new YT.Player(playerID, {
			events: { 'onReady': playYouTubeVideo }
		  });
		};  

		unloadYouTubePlayer = function(playerID) {
		  // This is the part that's broken
		  jQuery(playerID).stopVideo();
		};

		function playYouTubeVideo(event) {
		  event.target.playVideo();
		}

		jQuery('.show_player').click(function() {
			var idType = 'data-video-id';
			var id = jQuery(this).attr(idType);
			
			jQuery(this).fadeOut('fast', function() {
				jQuery('.hidden_player['+idType+'='+id+']').fadeIn('fast', function() {
					loadYouTubePlayer('the_player'+id);
					jQuery('.stop_player['+idType+'='+id+']').fadeIn('fast');
				});
			});
			return false;
		});
    
		jQuery('.stop_player').click(function() {
			var idType = 'data-video-id';
			var id = jQuery(this).attr(idType);
			
			jQuery(this).fadeOut('fast', function() {
				jQuery('.hidden_player['+idType+'='+id+']').fadeOut('fast', function() {
					unloadYouTubePlayer('the_player'+id);
					jQuery('.show_player['+idType+'='+id+']').fadeIn('fast');
				});
			});
		});

	
	
	/*
	//Administration hover
	jQuery(".administrationSmall a").mouseover(function() {
    	//jQuery(this).children("div").show();
		jQuery(this).children("h4").css('color','#d71a21');
		jQuery(this).children("p").css('color','#d71a21');
		jQuery(this).children("h4").css('text-decoration','none');
		jQuery(this).children("p").css('text-decoration','none');		
    })
	jQuery(".administrationSmall a").mouseout(function() {
    	//jQuery(this).children("div").hide();
		jQuery(this).children("h4").css('color','#000000');
		jQuery(this).children("p").css('color','#000000');
    })
	*/
	
    if (jQuery('.showreel .storyWrap > *').length > 1) {
        jQuery('.showreel .next,.carusel .prev').css('display','block');
        jQuery('.showreel .storyWrap').cycle({
            fx: 'fade',
            timeout: (6000),
            prev: '.prev',
            next: '.next',
			after: onAfter
        });

    }	
    
    function onAfter(curr,next,opts) {
    	var caption = (opts.currSlide + 1) + ' / ' + opts.slideCount;
    	jQuery('#caption').html(caption);
    }

    /** position fix for ie 7 to place focus boxes corretly **/
    jQuery('.infoAnimation li:last-child').addClass('last'); 





/* MEGA MENU */


//On Hover Over
function megaHoverOver(){
	jQuery(this).find('.hours').show();
	jQuery(this).find('.orderTable').hide();
    jQuery(this).find(".sub").stop().fadeTo('fast', 1).show();
}
//On Hover Out
function megaHoverOut(){
  jQuery(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      jQuery(this).hide();
	  jQuery(this).parent().siblings('.hours').show();
	  jQuery(this).parent().siblings('.orderTable').hide();
	    //after fading, hide it
  });
}

//Set custom configurations
var config = {
     sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)
     interval: 0, // number = milliseconds for onMouseOver polling interval
     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
     timeout: 0, // number = milliseconds delay before onMouseOut
     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
};






jQuery(".bottomNav li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
jQuery(".bottomNav li").hoverIntent(config); //Trigger Hover intent with custom configurations

jQuery(".catering a").click(function() {
    jQuery.fancybox({
            'padding'       : 0,
            'autoScale'     : false,
            'transitionIn'  : 'none',
            'transitionOut' : 'none',
            'title'         : this.title,
            'width'     : 680,
            'height'        : 495,
            'href'          : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
            'type'          : 'swf',
            'swf'           : {
                 'wmode'        : 'transparent',
                'allowfullscreen'   : 'true'
            }
        });

    return false;
});
	
});

