/* Dropdown Menu */
var site = function() {
	this.navLi = $('#nav li').children('ul').hide().end();
	this.init();
};

site.prototype = {
 	
 	init : function() {
 		this.setMenu();
 	},
 	
 	// Enables the slidedown menu, and adds support for IE6
 	
 	setMenu : function() {
 	
 	$.each(this.navLi, function() {
 		if ( $(this).children('ul')[0] ) {
 			$(this)
 				.append('<span />')
 				.children('span')
 					.addClass('hasChildren')
 		}
 	});
 	
 		this.navLi.hover(function() {
 			// mouseover
			$(this).find('> ul').stop(true, true).slideDown('fast');
 		}, function() {
 			// mouseout
 			$(this).find('> ul').stop(true, true).hide(); 		
		});
 		
 	}
 
}

/* Day Menu */
//variables a, i
var a;
var i=0;
// variable for main slider
var d = new Array; //height of the offer div
var start = true;

$(document).ready(function() {
new site();
a = $('.day-menu h1 a').length;
	if(a != 0){
		$('.offer').children().each(function(index){
			d[index] = $('.offer').children(':eq('+index+')').height();
		});
		test = d.sort().reverse();
		$('.offer').height(test[0]);
	}
	$('.offer').children(':not(:eq(0))').fadeOut(0);
    $('.day-menu h1 a').click(function(event){	// to do when the user clicks day menu anchor
		if( start == true && a > 1 ){
			start = false;  // set to false to prevent bubbling up the function
			event.preventDefault();
			event.stopPropagation();
			var b = $('.day-menu h1 a').index(this);	//get the index of the anchor
			int = clearInterval(int);
			$('.day-menu h1 a').removeClass('day-menu-slide');
			var l = $('.offer').children(':eq('+i+')').fadeOut('slow',function(){
				$('.day-menu h1 a:eq('+b+')').addClass('day-menu-slide');
				var r = $('.offer').children(':eq('+b+')').fadeIn('slow',function(){
					i = b;
					int=setInterval("re()",11000);		
					start = true;  //set to true to enable firing the function again
				});			
			});			
		}
		else{
			event.preventDefault();
		}
    });
});

// day menu function
function re(){

	if(a < 2){
		int = clearInterval(int);
		return false;
	}
	$('.offer').children(':eq('+i+')').fadeOut("slow",function(){
		i ++;
		if(i==a){ 
			i=0;
		}
		$('.day-menu h1 a').removeClass('day-menu-slide');
		$('.day-menu h1 a:eq('+i+')').addClass('day-menu-slide');
		$('.offer').children(':eq('+i+')').fadeIn('slow');
	});
}

var int=setInterval("re()",11000);

/**
 * jQuery.fullBg
 * Version 1.0
 * Copyright (c) 2010 c.bavota - http://bavotasan.com
 * Dual licensed under MIT and GPL.
 * Date: 02/23/2010
**/
(function($) {
  $.fn.fullBg = function(){
        var theWindow        = $(window),
            $bg              = $("#bg"),
            aspectRatio      = $bg.width() / $bg.height();

        function resizeBg() {
                if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
                    $bg
                        .removeClass()
                        .addClass('bgheight');
                } else {
                    $bg
                        .removeClass()
                        .addClass('bgwidth');
                }

        }

        theWindow.resize(function() {
                resizeBg();
        }); 
		resizeBg();
  };
})(jQuery)

