/*
* Copyright (c) 2008 Vinter (www.vinterwebb.se)
* Date: 2008-11-11
* Version 1.0
*/

var Vinter = {

	SubMenu: function(settings)
	{
		
		var settings = $.extend({
			nav: "ul#nav > li",
			main_link: ".topnav-main-link a",
			menu_trigger: ".topnav-submenu-trigger",
			menu_active_class: "active-submenu",
			menu_fade_speed: "fast"
		}, settings)
		
		/* Add hover & click events events */
		$(settings.nav)
			.click(function() {
				hideSub();
				//alert(1);
			    document.location.href = $(settings.main_link, this).attr("href");
			})
			.hover(function() {
				$(this).addClass("hover");
				hideSub();
			}, 
			function() {
				$(this).removeClass("hover");
			});
		
		
        $(".leftcol")
            .hover(function() {
				hideSub();
			});
			
			        $("img")
            .hover(function() {
				hideSub();
			});
						        $(".cycle")
            .hover(function() {
				hideSub();
			});
			
			
			

//		$(settings.menu_hide_id).hover(function(e) {
//			//hideSub();
//			alert(1);
//		});
		
		
		//$(document).click(function() {alert(1);hideSub();});
		/* Add menu toggle */
		$(settings.menu_trigger).hover(function(e) {
			$("ul", this.parentNode)
				.css({opacity: 0.9})
				.fadeIn(settings.menu_fade_speed);
			$(this.parentNode).addClass(settings.menu_active_class);
			// $(document).click(hideSubMenu);
		});
		

        $("footer").blur(function() {
				alert(123);
				});
		
		function hideSub() {
		    var d = $("." + settings.menu_active_class);
			$("ul", d).fadeOut(settings.menu_fade_speed);
			d.removeClass(settings.menu_active_class);
			$(document).unbind("click");
		}
		
		function hideSubMenu(e) {
		    var d = $("." + settings.menu_active_class);
			$("ul", d).fadeOut(settings.menu_fade_speed);
			d.removeClass(settings.menu_active_class);
			$(document).unbind("click");
		}
	},

	Init: function()
	{
        // Append class to body if IE < 7
        // Do this so we don't need conditional comments
        if($.browser.msie === true && parseInt($.browser.version) <= 6)
        {
            // Add png8 to body... 
            $("body").addClass("png8");
            document.execCommand('BackgroundImageCache', false, true);
        }

        Vinter.SubMenu({
            nav: "ul#nav > li"
        });

        $("#bookingMainIframe").load(function() {
			// only for development
			$("bookingLoader").hide();

			// use the line below in production
			//$("#bookingMainIframe").css("height", 0);
        });
        
        
        if (typeof $().formHints == "function")
		{
			$("form").formHints({
				css_class: "preview-value",
				elements: ".text-hint"
			});
		}
		
		$("#searchForm .text").bind("focus", function() {
			 $(this).css({
				width: "181px"
			 });
		});
		
		$("#searchForm .text").bind("blur", function() {
			 $(this).css({
				width: "181px"
			 });
		});
		
		$("#searchBottomForm .text").bind("focus", function() {
			 $(this).css({
				width: "181px"
			 });
		});
		
		$("#searchBottomForm .text").bind("blur", function() {
			 $(this).css({
				width: "181px"
			 });
		});
		
		
		$('#selectBookmark').bookmark({hint: '{s}' ,sites: 
            ['facebook', 'delicious', 'digg', 'google', 'stumbleupon', 'twitter']});
		
		
		$(function() {
            //$('.jCarouselLite a').lightBox({fixedNavigation:true});
            //$('a[rel=lightbox]').lightBox({imageBtnClose:'../../../../../../images/common/loader.gif'}); 
            $('a[rel=lightbox]').lightBox(); 
        });
        
        
		
		
		
		
		
            $(".cycle")
			//.after('<div id="pager"></div>')
			.cycle({
				pager: "#pager",
				pagerEvent: 'mouseover',
				timeout: 5000,
				pause: 1,
				next: "#nextslide",
				after: function()
				{
					var next = $(this).next();
				
					if (next.length == 0)
						next = $(this.parentNode).children().eq(0);
				
				$("#nextslide").html($("h2", next).text());
				     
				}
		});
		$('#pauseButton').click(function() { 
		   
            $('.cycle').cycle('pause'); 
             $('#pauseButton').hide();
             $('#playButton').show(); 
        });
        
        $('#playButton').click(function() { 
            $('.cycle').cycle('resume'); 
             $('#playButton').hide();
             $('#pauseButton').show(); 
        });
        
        $('#playButton').hide();
        $('#pauseButton').show();
		
		
		
		
//		$(".accordion").accordion({
//			header: 'a.accordion-title'
//        });


       
//            $(".jCarouselLite").jCarouselLite({
//                btnNext: ".next",
//                btnPrev: ".prev",
//                speed: 800,
//                visible: 3,
//                scroll: 1
//            });
//        

//        
//            //$('.jCarouselLite a').lightBox({fixedNavigation:true});
//            $('a[@rel*=lightbox]').lightBox(); 
        
		

	}

}

// Add load events
$().ready(Vinter.Init);