/**
 * @project: chocolaterie van hoorebek
 * @location: 
 * @date: 02.07.2010
 * @author: Simon Coudeville & Simon Saelens
 * @description: Core logic
 */

Cufon.set('fontFamily', 'Porcelain').replace('h1')('h2')('h3')('.FirstLetter');


/**
 * Create the CHOCO object variable is it is undefined
 */
 
if(typeof $.CHOCO == "undefined") {
	$.CHOCO = Object;
}

$.CHOCO.animate		=		{
	execute		:		function(){
		
		if ($("div#makeMeScrollable").length != 0) {$("div#makeMeScrollable").smoothDivScroll({scrollingSpeed: 12, mouseDownSpeedBooster: 3})};
		
		$("#closeie6warning").bind({
			click: function (){$("#ie6_banner").hide();}
		});
		
		if($('.lightbox').length > 1){
			$(".lightbox").fancybox({
				overlayColor:'#3C180F',
				titleShow: false,
				overlayOpacity:'0.5'
			});
		}

		$.CHOCO.animate.goFooterCookie();
		$.CHOCO.animate.animateFooter();
		$.CHOCO.animate.animatePopups();
		$.CHOCO.animate.swimSuperFish();
	},
	
	swimSuperFish		:	function() {
		if ($('#topmenu').length != 0) {
			$('#topmenu').superfish({
					dropShadows: false,
					animation: {height:'show'},
					speed: 200,
					delay: 100,
					autoArrows: true 
				});
		}
	},
	
	goFooterCookie		:		function(){
		
		if($('#footer').length > 1){
			var $cookie_name = "footerPosition";
			if($.cookie($cookie_name)) {
				
				var footerposition = $.cookie($cookie_name);
				switch(footerposition){
					case 'up':
						break;
					case 'down':
						$("#footerHolder").css({bottom: '-240px'});
						$("#contentHolder").css({marginBottom: '0'});
						$.CHOCO.animate.animateUpButton();
						break;
				};
			}
		}
		
	},
	
	animateFooter		:		function() {
		
		$("#downButton").bind({
			mouseenter: function(){
				$("#downButton").animate({top: '10px'}, 100);
			},
			mouseleave: function(){
				$("#downButton").animate({top: '0px'}, 100);
			},
			mouseup: function() {
				// go down !! footerholder ...
				$.cookie('footerPosition','down', {path:'/'});
				$("#downButton").unbind();
				$(".PicHover").unbind();
				$("#footerHolder").css({bottom: '0'}).delay(500).animate({bottom: '-240px'}, 500, function(){
						$("#contentHolder").css({marginBottom: '0'});
						$.CHOCO.animate.animateUpButton();
				});	
					
			}
		});
		
	},
	
		
	animateUpButton		: 		function() {
		
		$("#upButton").animate({top: '-200px'}, 500);
			
		$("#upButton").bind({
			mouseenter: function(){
				$("#upButton").animate({top: '-210px'}, 100);
			},
			mouseleave: function(){
				$("#upButton").animate({top: '-200px'}, 100);
			},
			mouseup: function() {
				// come back !! i miss you navholder ...
				$.cookie('footerPosition','up', {path:'/'});
				$("#upButton").unbind();
				$("#upButton").animate({top: '200px'}, 500);
				$("#footerHolder").delay(500).animate({bottom: '0'}, 500, function(){
						$.CHOCO.animate.animateFooter();
						$.CHOCO.animate.animatePopups();
				});	
				
			}
		});	
		
	},
	
	animatePopups		:		function() {
		$(".PicHover").bind({
			mouseenter: function(){
				var hoverID = $(this).attr("id");
				var popupID = '#' + hoverID + 'Popup'
				$(popupID).show().stop().animate({bottom: '210px'}, 100);

			},
			mouseleave: function(){
				var popupID = $(this).attr("id") + 'Popup';
				$('#' + popupID).stop().animate({bottom: '200px'}, 100).hide();
				
			}
		});
	}
}

$(document).ready(function() {
	$.CHOCO.animate.execute();
});

