﻿
$(function () {
    Unilever.Layer.basic();
    Unilever.Layer.brand();
    Unilever.Layer.code();
	
	if($('input.exclusive').length) {
		ExclusiveData.init();
	}
	
	//$("select, input:checkbox, input:radio").uniform();
	
	
	
	// CLOUD CAROUSEL
    
    $(document).ready(function() {
    
        $("#slideshow").css("overflow", "hidden");

        $("ul#slides").cycle({
        fx: 'fade',
        timeout:0,
        pause: 1,
        prev: '#prev',
        next: '#next',
        pager:  '#nav', 
        pagerAnchorBuilder: function(idx, slide) { 
        // return selector string for existing anchor 
        return '#nav li:eq(' + idx + ') a'; 
        }
        });

    });
    
	
	$("#home_product_carousel").find('.product_carousel').CloudCarousel(		
		{			
			xPos: 275,
			yPos: 100,
			minScale: 0.30,
			yRadius:-0.25,
			xRadius:380,
			buttonLeft: $("#home_product_carousel").find(".left_button"),
			buttonRight: $("#home_product_carousel").find(".right_button"),
			bringToFront: true
		}
	);
    
   // *** carousel tooltip *** 
	var carouselImg = $(".product_carousel img");
	var carouselTooltip = $("#carouselTooltip");
	
	carouselImg.mouseenter(function(){
		var zIndex = $(this).css("z-index");
		if (parseInt(zIndex) > 60) {
			var tooltipData = $(this).data("tooltip");
			tooltipData = tooltipData.split("||");
			carouselTooltip.find("h2").text(tooltipData[0] );
			carouselTooltip.find("a").attr("href", tooltipData[1] );
			if($.browser.msie){
				carouselTooltip.show();
			} else {
				carouselTooltip.fadeIn(500);
			}
		}
	});
    
    $(".right_button").click(function() { hideTooltip(); }); 
	$(".product_carousel").mouseleave(function() { hideTooltip(); }); 
	carouselImg.click(function() { hideTooltip(); }); 
	var hideTooltip = function () {
		if($.browser.msie){
			carouselTooltip.hide();
		} else {
			carouselTooltip.fadeOut(500);
		}
	};
    
    // jQuery method
	$('video').mediaelementplayer({
    // the order of controls you want on the control bar (and other plugins below)
    features: ['playpause','progress','current','duration','tracks','volume','fullscreen'],
    });
	
});

var Unilever = {};

Unilever.Layer = {
	basic: function() {
		var BasicLayer = $('#basicLayer');
		$('a.openlayer').live('click', function(e) {
			var uri = $(this).attr('href');
			e.preventDefault();
			BasicLayer.show();
			$('#main').addClass('overlay');
			BasicLayer.find('.box-layer').load(uri + ' #content');
			
			BasicLayer.find('a.openInLayer').live('click', function(e) {
				var uri = $(this).attr('href');
				e.preventDefault();
				BasicLayer.find('.box-layer').load(uri + ' #content');
			});
		});
		BasicLayer.find('a.close').live('click', function(e) {
			e.preventDefault();
			BasicLayer.find('.box-layer').html('Lade...');
			BasicLayer.hide();
			$('#main').removeClass('overlay');
		});
	},
    brand: function() {
        var BrandsLayer = $('#unileverBrands');
        $('a#linkUnileverGroup').live('click', function(e) {
            e.preventDefault();
            BrandsLayer.show();
			$('#main').addClass('overlay');
            BrandsLayer.find('a.close').live('click', function(e) {
                e.preventDefault();
                BrandsLayer.hide();
				$('#main').removeClass('overlay');
            });
        });
    },
    code: function() {
        var CodeLayer = $('#codeHelp');
        $('a.captchaHelpLayerTrigger').live ('click', function(e) {
            e.preventDefault();
            CodeLayer.show();
			$('#main').addClass('overlay');
            CodeLayer.find('a.close').live('click', function(e) {
                e.preventDefault();
                CodeLayer.hide();
				$('#main').removeClass('overlay');
            });
        });
    }
};

/* Sweepstake */
var ExclusiveData = {
	all: 'exclusive-all',
	only: 'exclusive-only',
	init: function() {
		var _this = this;
		$('input.exclusive').live('change', function() {
			_this.checkFormFields($(this));
		});
	},
	checkFormFields: function(e) {
		var _this = this;
		if(e.attr('checked') === "checked" || e.attr('checked') === true) {
			if(e.hasClass(_this.all)) {
				$('input.'+_this.only).attr('checked', false);
			} else {
				$('input.'+_this.all).attr('checked', false);
			}
			$.uniform.update();
		}		
	}
};
