/*var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();*/

/*
if((BrowserDetect.browser == 'Firefox') && (BrowserDetect.OS=='Mac')) {
	alert('FF mac');
	$('object').css('position','relative');
	$('object').css('z-index','relative');
}
*/


function savePreference() {
  var str = $("#preference-form").serialize();
  $.post("user/updatePreference",str,
      function(data){
        $('#content').html(data);
        $('#content select.dropdown:visible').selectbox();
        
        $(window).unbind('click');
      });
}

function loadFunction() {
	// Fix problem when resizing to smaller under IE7
	if($.browser.msie) {
		$('body').css('min-width','950px');
	}
}

$(window).load(loadFunction);

/**
 * @author tparisot
 */
(function($){
  /**
   * Custom functions to apply or used as callbacks
   */
  VODKA.container = '#general-container';
  VODKA.initAjaxNavigation = function (object) {
  	$('a',object).ajaxNavigation({
        basepath:     VODKA.baseuri,
        onStart:      VODKA.ajaxStart,
        onExecution:  VODKA.ajaxExecution,
        to:           VODKA.container
      });
  }
  
  /*
   * Init select
   */
   VODKA.initSelect = function () {
   	/*
     * Customize dropdowns
     */
    $('select.dropdown:visible').selectbox();
    
    // Unbind event put by selectbox to solve FF and safari issue
    $(window).unbind('click');
    
	$('.div-selectbox .selectbox').unbind('blur');
	$('.div-selectbox').bind('mouseleave',function(){$('.selectbox',this).blur();$('.selectbox',this).resize()});
    
    /*$('.div-selectbox .selectbox').bind('mouseleave',function(){
    	$(this).blur2();
    });*/
    
    //$('.div-selectbox').bind('mouseleave',function(){$('.selectbox',this).blur()});
    //$('.div-selectbox').bind('mouseleave',function(){$('.selectbox',this).blur()});
    //$('.div-selectbox .selectbox').unbind('blur');
    
    /*** For filter and sort select ***/
    // We have a border, so we must decrease wrapper div width     
    $('.filter-div .selectbox-wrapper').each(function(){$(this).width($(this).width() -2)});
    // can't click on "optgroup" option
    $('.filter-div li.group').unbind('click');
    // to solve problems, hide on leaving
    $('.filter-ingredient').bind('mouseleave',function(){$('.selectbox',this).blur()});
    $('.sort-order').bind('mouseleave',function(){$('.selectbox',this).blur()});
    /*************************************************/
   }
  
  VODKA.init = function(){
    /*
     * Ajax navigation
     */
    $('a').ajaxNavigation({
      basepath:     VODKA.baseuri,
      onStart:      VODKA.ajaxStart,
      onExecution:  VODKA.ajaxExecution,
      to:           VODKA.container
    });
    
    /*
     * Empty fields on click
     * @todo pluginize with field repopulation if needed
     */
    $('#search-input, #filter_by_text, #query').click(function(){ 
      $(this).val('');
    });
    
    // Special link for search form
    // TODO : improve that
    $('#search').bind('submit',function(){
    	url = $('#search-hidden-link').attr('href');
    	query = $('#query',this).val();
    	query = query.replace(/\s/g,'+');
    	//query = query.replace(/&/g,'&amp;');
    	$('#search-hidden-link').attr('href',url+'?commit=Go&query='+query);
    	$('#search-hidden-link').click();
    	return false;
    });
    
    // Special link for filters form
    // filter_by_text=Keywords&commit=Go&filter_by=&sort_by=color
    // TODO : improve that
    $('#filters').bind('submit',function(){
    	url = $('#filters-hidden-link').attr('href');
    	
    	text = '';
    	if($('#filter_by_text',this).length && $('#filter_by_text',this).val()!='Keywords') {
	    	text = $('#filter_by_text',this).val();
	    	text = text.replace(/\s/g,'+');
	    	text = '&filter_by_text='+text;
    	}
    	
    	filter_by = '';
    	if($('#filter_by',this).length) {
    		filter_by = $('#filter_by',this).val();
    		filter_by = filter_by.replace(/\s/g,'+');
    		filter_by = '&filter_by='+filter_by;
    	}
    	
    	sort_by = '';
    	if($('#sort_by',this).length) {
	    	sort_by = $('#sort_by',this).val();
	    	sort_by = sort_by.replace(/\s/g,'+');
	    	sort_by = '&sort_by='+sort_by;
    	}
    	
    	$('#filters-hidden-link').attr('href',url+'?commit=Go'+text+filter_by+sort_by);
    	$('#filters-hidden-link').click();
    	return false;
    });

    
    // Init selectbox
    VODKA.initSelect();

    /*
     * Highlight left panel items
     */
    $('#side-section-map>li')
      .bind('mouseenter', function(){
      	if($(this).hasClass('active')) {
      		// keep the initialy active box
      		$(this).addClass('alreadyactive');
      	}
        $(this).addClass('active');
      })
      .bind('mouseleave', function(){
      	if(!$(this).hasClass('alreadyactive')) {
	        $(this).removeClass('active');
	        //$('#side-section-map>li.active').addClass('active');
        }
      });
     
     /*
       * Map of the homepage
       * Ease the application of a unique function over this array
       * active_image : used for current section
       */
      var sidemap = [
        {id: '#side-section-map li.century',         active_image: '/images/themes/sitemap/20th-century.jpg',			image: '/images/themes/sitemap_hover/20th-century.jpg',  		flash: '/movie/homepage/hp-century.swf',       height: 50,  width: 74},
        {id: '#side-section-map li.stcentury',       active_image: '/images/themes/sitemap/21st-century.jpg',           image: '/images/themes/sitemap_hover/21st-century.jpg',		 	flash: '/movie/homepage/hp-century-21.swf',    height: 74,  width: 74},
        {id: '#side-section-map li.expertise',       active_image: '/images/themes/sitemap/expertise.jpg',              image: '/images/themes/sitemap_hover/expertise.jpg',			flash: '/movie/homepage/hp-expertise.swf',     height: 60,  width: 74},
        {id: '#side-section-map li.friends',         active_image: '/images/themes/sitemap/family.jpg',                 image: '/images/themes/sitemap_hover/family.jpg',				flash: '/movie/homepage/hp-friends-family.swf',height: 123,  width: 74},
        {id: '#side-section-map li.rituals',         active_image: '/images/themes/sitemap/rituals.jpg',                image: '/images/themes/sitemap_hover/rituals.jpg',  			flash: '/movie/homepage/hp-rituals.swf',       height: 123,  width: 82},
        {id: '#side-section-map li.glossary',        active_image: '/images/themes/sitemap/glossary.jpg',               image: '/images/themes/sitemap_hover/glossary.jpg',  			flash: '/movie/homepage/hp-glossary.swf',      height: 36,  width: 74},
        {id: '#side-section-map li.imperial-decree', active_image: '/images/themes/sitemap/imperial.jpg',               image: '/images/themes/sitemap_hover/imperial.jpg',				flash: '/movie/homepage/hp-imperial.swf',      height: 61,  width: 82},
        {id: '#side-section-map li.ingredients',     active_image: '/images/themes/sitemap/ingredients.jpg',            image: '/images/themes/sitemap_hover/ingredients.jpg',			flash: '/movie/homepage/hp-ingredients.swf',   height: 39,  width: 82},
        {id: '#side-section-map li.mendeleev',       active_image: '/images/themes/sitemap/mendeleev.jpg',              image: '/images/themes/sitemap_hover/mendeleev.jpg',			flash: '/movie/homepage/hp-mendeleev.swf',     height: 29,  width: 82},
        {id: '#side-section-map li.origin-pt1',      active_image: '/images/themes/sitemap/origins-1.jpg',              image: '/images/themes/sitemap_hover/origins-1.jpg',			flash: '/movie/homepage/hp-origins-1.swf',     height: 81,  width: 82},
        {id: '#side-section-map li.origin-pt2',      active_image: '/images/themes/sitemap/origins-2.jpg',              image: '/images/themes/sitemap_hover/origins-2.jpg',			flash: '/movie/homepage/hp-origins-2.swf',     height: 81,  width: 74},
        {id: '#side-section-map li.process',         active_image: '/images/themes/sitemap/process.jpg',                image: '/images/themes/sitemap_hover/process.jpg',				flash: '/movie/homepage/hp-process.swf',       height: 40,  width: 82},
        {id: '#side-section-map li.spirit',          active_image: '/images/themes/sitemap/russian-spirit.jpg',         image: '/images/themes/sitemap_hover/russian-spirit.jpg', 		flash: '/movie/homepage/hp-spirit.swf',        height: 40,  width: 74},
        {id: '#side-section-map li.brands',          active_image: '/images/themes/sitemap/brands.jpg',        			image: '/images/themes/sitemap_hover/brands.jpg', 				height: 92,  width: 82},
        {id: '#side-section-map li.fame',            active_image: '/images/themes/sitemap/fame.jpg',          			image: '/images/themes/sitemap_hover/fame.jpg',					height: 50,  width: 158},
        {id: '#side-section-map li.tips',            active_image: '/images/themes/sitemap/tips.jpg',         			image: '/images/themes/sitemap_hover/tips.jpg',					height: 81,  width: 82},
        {id: '#side-section-map li.gourmet',         active_image: '/images/themes/sitemap/gourmet.jpg',       			image: '/images/themes/sitemap_hover/gourmet.jpg',				height: 102,  width: 74},
        {id: '#side-section-map li.mix',             active_image: '/images/themes/sitemap/mix.jpg',           			image: '/images/themes/sitemap_hover/mix.jpg',					height: 92,  width: 82},
        {id: '#side-section-map li.goingout',        active_image: '/images/themes/sitemap/goingout.jpg',      			image: '/images/themes/sitemap_hover/goingout.jpg',				height: 71,  width: 74},
        {id: '#side-section-map li.news',            active_image: '/images/themes/sitemap/news.jpg',          			image: '/images/themes/sitemap_hover/news.jpg',					height: 60,  width: 158},
        {id: '#side-section-map li.contributors',    active_image: '/images/themes/sitemap/contributors.jpg',  			image: '/images/themes/sitemap_hover/contributors.jpg',			height: 50,  width: 80},
        {id: '#side-section-map li.responsability',  active_image: '/images/themes/sitemap/nothing.jpg',       			image: '/images/themes/theme-hp-nothing.jpg',					height: 50,  width: 80},
        {id: '#side-section-map li.terms',           active_image: '/images/themes/sitemap/nothing.jpg',       			image: '/images/themes/theme-hp-nothing.jpg',					height: 50,  width: 78},
        {id: '#side-section-map li.contact',         active_image: '/images/themes/sitemap/nothing.jpg',       			image: '/images/themes/theme-hp-nothing.jpg',					height: 50,  width: 74},
        {id: '#side-section-map li.privacy',         active_image: '/images/themes/sitemap/nothing.jpg',       			image: '/images/themes/theme-hp-nothing.jpg',					height: 50,  width: 74},
        {id: '#side-section-map li.about',           active_image: '/images/themes/sitemap/nothing.jpg',       			image: '/images/themes/theme-hp-nothing.jpg',					height: 50,  width: 74},
        {id: '#side-section-map li.vip',           	 active_image: '/images/themes/sitemap/nothing.jpg',       			image: '/images/themes/theme-hp-nothing.jpg',	 				height: 50,  width: 74}
      ];

      /*
       * Sidemap construction
       * We iterate over each item of a given array
       */
      $.each(sidemap, function(){
        var row = this;
        //.css('background-image', 'url('+ $('img', row.id).attr('src') +')')
        if($(row.id).hasClass('item-active'))
        {
        	$('a:first', row.id).css('background', 'url('+row.active_image+')');
        }
        
        $(row.id).one('mouseenter', function(){
          $('a.title-on', this).css('background', 'url('+row.image+')')
          $('a.title-on-contact', this).css('background', 'url('+row.image+')')
          if (row.flash) {
            $('a.title-on', this).flash({
              src: row.flash,
              height: row.height,
              width: row.width,
              wmode: 'transparent',
              href: $('a.title-on', this).attr('href')
            });
            
            // pb : <a> is added, we have to delete it
            temp = $('a.title-on', this).html();
            temp = temp.replace(/<a>(.*?)<\/a>/,'$1');
            $('a.title-on', this).html(temp);
          }
        });
      });
      
      $('#side-section-map>li>ul.items>li')
      .bind('mouseenter', function(){
      
      	/*$('#side-section-map>li>ul.items>li').each(function(){
      	  aObject = $('a.title-on', this); 
	      $('a:first', this).show();
	      aObject.hide();
	      //$('a.title-on', $('#side-section-map>li>ul.items>li.item-active')).show();
	      
	      //this.style.overflow = 'hidden';
	      //$('ul#side-section-map').css('overflow','hidden');
	      //$('ul#side-section-map ul').css('overflow','hidden');
	      
	      //$('#side-section-map>li>ul.items>li').css('z-index','1');
    	  VODKA.cancelHovering(aObject);
    	});*/
      
        if(!$(this).hasClass('coming-soon')) {
	      $('a.title-on', this).show();
	      $('a:first', this).hide();
	      
	      this.style.overflow = 'visible';
	      $('ul#side-section-map').css('overflow','visible');
	      $('ul#side-section-map ul').css('overflow','visible');
	      
	      // Find the current sidemap section
	      currentSection = null;
	      className = this.className.split(' ')[0]
	      for(var i=0; i<sidemap.length; i++) {
	      	if(sidemap[i].id == '#side-section-map li.'+ className) {
	      		currentSection = sidemap[i];
	      		break;
	      	}
	      }
	      
	      VODKA.processHovering($('a.title-on', this),currentSection);
        }
      });
      
      $('#side-section-map>li>ul.items>li').
      	bind('mouseleave', function(){
		    if(!$(this).hasClass('coming-soon')) {
		      $('a:first', this).show();
		      $('a.title-on', this).hide();
		      VODKA.cancelHovering($('a.title-on', this));
	         }
	     });
      
      /*$('#side-section-map>li>ul.items>li').
      	bind('mouseleave', function(){
		    if(!$(this).hasClass('coming-soon')) {
		      $('a:first', this).show();
		      $('a.title-on', this).hide();
		      //$('a.title-on', $('#side-section-map>li>ul.items>li.item-active')).show();
		      
		      this.style.overflow = 'hidden';
		      $('ul#side-section-map').css('overflow','hidden');
		      $('ul#side-section-map ul').css('overflow','hidden');
		      
		      $('#side-section-map>li>ul.items>li').css('z-index','1');
		      
		      // Find the current sidemap section
		      //for(var i=0; i<sidemap.length; i++) {
		      //	if(sidemap[i].id == '#side-section-map li.'+ this.className) {
		      //		currentSection = sidemap[i];
		      //		break;
		      //	}
		      //}
		      
		      VODKA.cancelHovering($('a.title-on', this));
	         }
	     });*/
      
      

    /**
     * Homepage
     */
    // hover effect for a news list item
    if ($('#vodka-section').hasClass('homepage'))
    {
      /*
       * Change background : OLD way
       */
      //$('body').css('background', '#5d5d5d url("/images/sample/bgbar-hp.jpg") repeat-x');
      //$('#background').css('background', 'url("/images/sample/bg-hp.jpg") no-repeat center top');  
      
      $('#nav-news li .title-on').hide();
      $('#nav-news li .title-off').hide();
      $('#nav-news li')
        .bind('mouseenter', function(){ 
          $(this).addClass("active");
          $('a', this).html($('div.title-on', this).html());
        })
        .bind('mouseleave', function(){ 
          $(this).removeClass("active"); 
          $('a', this).html($('div.title-off', this).html());
        })
        .bind('click', function(){ $('a', this).click(); });
  
  
      // hover effect for a sitemap items
      $('#section-map li.content-box ul.items')
        .bind('mouseenter', function(){ $(this).addClass('items-active'); })
        .bind('mouseleave', function(){ $(this).removeClass('items-active'); });
        
      $('#section-map ul.items > li')
        .bind('mouseenter', function(){ $('a.theme', this).show(); })
        .bind('mouseleave', function(){ $('a.theme', this).hide(); })
        .bind('click', function(){ $('a.theme', this).click(); });

      //Highlight on section titles on home page
      //-- Myths
      $('#section-map li.myth h2')
        .bind('mouseenter', function() { $('#section-map li.myth ul.items').addClass('items-active'); })
        .bind('mouseleave', function() { $('#section-map li.myth ul.items').removeClass('items-active'); })
      
      //-- Vodkapedia  
      $('#section-map li.vodkapedia h2')
        .bind('mouseenter', function() { $('#section-map li.vodkapedia ul.items').addClass('items-active'); })
        .bind('mouseleave', function() { $('#section-map li.vodkapedia ul.items').removeClass('items-active'); })
      
      //-- Kulture  
      $('#section-map li.kulture h2')
        .bind('mouseenter', function() { $('#section-map li.kulture ul.items').addClass('items-active'); })
        .bind('mouseleave', function() { $('#section-map li.kulture ul.items').removeClass('items-active'); })
      
      //-- Taste  
      $('#section-map li.taste h2')
        .bind('mouseenter', function() { $('#section-map li.taste ul.items').addClass('items-active'); })
        .bind('mouseleave', function() { $('#section-map li.taste ul.items').removeClass('items-active'); })
      
      //-- Pro  
      $('#section-map li.pro h2')
        .bind('mouseenter', function() { $('#section-map li.pro ul.items').addClass('items-active'); })
        .bind('mouseleave', function() { $('#section-map li.pro ul.items').removeClass('items-active'); })
      //End highlight on section titles on home page
      
      /*
       * Map of the homepage
       * Ease the application of a unique function over this array
       */
      var map = [
        {id: '#section-map li.century-20',         flash: '/movie/homepage/hp-century.swf',       height: 71,  width: 106},
        {id: '#section-map li.century-21-spirit',  flash: '/movie/homepage/hp-century-21.swf',    height: 106, width: 106},
        {id: '#section-map li.expertise',          flash: '/movie/homepage/hp-expertise.swf',     height: 86,  width: 106},
        {id: '#section-map li.friends',            flash: '/movie/homepage/hp-friends-family.swf',height: 176, width: 105},
        {id: '#section-map li.rituals',            flash: '/movie/homepage/hp-rituals.swf',       height: 176, width: 118},
        {id: '#section-map li.glossary',           flash: '/movie/homepage/hp-glossary.swf',      height: 52,  width: 106},
        {id: '#section-map li.imperial-decree',    flash: '/movie/homepage/hp-imperial.swf',      height: 87,  width: 117},
        {id: '#section-map li.ingredients',        flash: '/movie/homepage/hp-ingredients.swf',   height: 56,  width: 117},
        {id: '#section-map li.mendeleev',          flash: '/movie/homepage/hp-mendeleev.swf',     height: 41,  width: 117},
        {id: '#section-map li.origins-1',          flash: '/movie/homepage/hp-origins-1.swf',     height: 116, width: 117},
        {id: '#section-map li.origins-2',          flash: '/movie/homepage/hp-origins-2.swf',     height: 116, width: 106},
        {id: '#section-map li.process',            flash: '/movie/homepage/hp-process.swf',       height: 57,  width: 117},
        {id: '#section-map li.spirit',             flash: '/movie/homepage/hp-spirit.swf',        height: 57,  width: 105}
      ];

      /*
       * Homepage construction
       * We iterate over each item of a given array
       */
      $.each(map, function(){
        var row = this;
        //
        $(row.id).one('mouseenter', function(){
          $('a.theme', this)
            .css('background-image', 'url('+ $('img', this).attr('src') +')')
            .flash({
              src: row.flash,
              height: row.height,
              width: row.width,
              wmode: 'transparent',
              href: $('a.theme', this).attr('href')
            })
          // pb : <a> is added, we have to delete it
           temp = $('a.theme', this).html();
           temp = temp.replace(/<a>(.*?)<\/a>/,'$1');
           $('a.theme', this).html(temp);
        });
      });
    }

    /**
     * Grid Layout
     */
    else if ($('#vodka-section').hasClass('grid'))
    {
      VODKA.initGridBox();
      
      /*
       * Change background : OLD way
       */
      //$('body').css('background', '#1e201f url("/images/sample/bgbar-mix.jpg") repeat-x');
      //$('#background').css('background', 'url("/images/sample/bg-mix.jpg") no-repeat center top');
      //$('#page').css('background', 'url("/images/sample/bgpt2.png") repeat');
    }

    /**
     * Grid Opened
     */
    else if ($('#vodka-section').hasClass('grid-open'))
    {
      VODKA.initGridBox();
      
      /*
       * Split initial content
       * splitText(content, width, height)
       */
      htmlText = $('#item-content').html();
      
      if(htmlText.length > 1) {
	      // We have to close param and embed tabs, or Columns.splitText will do bad things...
	      htmlText = htmlText.replace(/<param([^>]*?)>/gi,'<param$1 />');
	      htmlText = htmlText.replace(/<embed([^>]*?)>/gi,'<embed$1 />');
      }
      
      //var columns = Columns.splitText(htmlText, 351, 315);
      //var columns = Columns.splitText(htmlText, 330, 315);
      //var columns = Columns.splitText(htmlText, 335, 335);
      
      //var columns = Columns.splitText(htmlText, 285, 287);
      //var columns = Columns.splitText(htmlText, 400, 400);
      //var columns = Columns.splitText(htmlText, 287, 300);
      var columns = Columns.splitText(htmlText, 287, 299);

      for (var i = 0, columns_length = columns.length; i < columns_length; i ++)
      {
        $('#view-inside').append('<li class="injected-column">'+columns[i]+'</li>');
        // Check if the column contains a full-size image. If yes - put to its container an additional class which will increase its size
        if (columns[i].indexOf('full-picture') != -1 || columns[i].indexOf('full-movie') != -1)
        {
          $('#view-inside li.injected-column:last').addClass('media-column');
        }
      }

      /*
       * - Append comments
       * - Shift rating and comments badge to the first column
       * - Append a fake <li> to fix the item scrolling issues : another problem appears with that...
       */
      $('#comments-column').appendTo('#view-inside');
      
      //$('#view-info, #view-rating').appendTo('#view-inside>li:first');
      $('#view-rating-comments').appendTo('#view-inside>li:first');
      
      $('#item-content').remove();
      /*$('#view-inside').append('<li></li>');*/
      $('#view-inside').append('<li></li>');

      /*
       * Instantiate the carousel
       * - bottomside navigation (1 - n boxes with prev/next buttons to navigate through columns)
       */
       var noBody = false;
       $('#view-inside').jcarousel({ scroll: 1, animation: 'fast', initCallback: function(carousel){
        /* build the list of navigation links. the loop ommits the last fake <li> */
        //for (var j = 1; j <= ($('#view-inside>li').size()-1); j ++)
        
        // If we have 3 columns, it seems that we have no description
        // so on number 2, we scroll to number 3
        // and we forget the number 3
        columnSize = $('#view-inside>li').size()-1;
        
        if(columnSize==3) {
        	noBody = true;
        }
        
        for (var j = 1; j <= columnSize; j ++)
        {
          if(noBody && j==2) {
          	$('#carousel-nav').append('<li id="nav_item_'+3+'" class="item"><a href="#" class="nava_'+3+'">'+2+'</a></li>');
          }
          else {
          	if(!(noBody && j==3)) {
          		$('#carousel-nav').append('<li id="nav_item_'+j+'" class="item"><a href="#" class="nava_'+j+'">'+j+'</a></li>');
          	}
          }
        }
        /* prev/next arrows */
        $('#carousel-nav').prepend('<li class="prev"><a href="#">Previous</a></li>');
        $('#carousel-nav').append('<li class="next"><a href="#">Next</a></li>');

        /* set the first navigation element active */
        $('#carousel-nav li.item:first').addClass("active");

        /*
         * Link on comments scrolls to the latest column
         */
        $('#view-inside div#view-info span.comments-nb a').bind('click', function() {
            carousel.scroll($('#carousel-nav li').length);
            $('#carousel-nav li').removeClass("active");
            $('#carousel-nav li.item:last').addClass("active");
            return false;
        });
        

        //fix a problem of comments column which was not appearing due to the Carousel
        $('#view-inside').width($('#view-inside').width()+70);

        /*
         * Link on a numbered item scrolls to its corresponding column
         */
        $('#carousel-nav li.item a').bind('click', function() {
		    if ($.jcarousel.intval($(this).text()) == 1) {
				document.getElementById('view-inside').style.marginLeft = "-60px";
				//$('.rating').css('padding-left', "62px");
			} else {
				document.getElementById('view-inside').style.marginLeft = "0px";
			}
			document.getElementById('view-inside').style.paddingLeft = "64px";
			$('.jcarousel-next').css('visibility', "visible");


			if (!$(this).parent().next().hasClass("item")) {
				document.getElementById('view-inside').style.paddingLeft = "128px";
				$('.jcarousel-next').css('visibility', "hidden");
			}
			
			// Update
			// we don't use text, but class
			number = $(this).text();
			
			numberTemp = $(this).attr('class').split('_');
			if(numberTemp[numberTemp.length-1]) {
				number = numberTemp[numberTemp.length-1];
			}
            carousel.scroll($.jcarousel.intval(number));
            $('#carousel-nav li').removeClass("active");
            $(this).parent().addClass("active");
            return false;
        });

        /*
         * Next navigation button
         */
        $('#carousel-nav li.next a').bind('click', function(){
            $('#item-view div.jcarousel-next').trigger('click');
            return false;
        });
        $('#item-view div.jcarousel-next').bind('click', function(){
          // We check the noBody var, to know if we have to ignore the second column
          if(noBody && (carousel.first==1)) {
            // Simulate a click on number 2
            $('a.nava_3').click();
          }
          else {
	          if ($('#view-inside>li.jcarousel-item-'+(carousel.first+1)).is(":last"))
	          {
				if (carousel.first+1 == 1) {
					document.getElementById('view-inside').style.marginLeft = "-60px";
				} else {
					document.getElementById('view-inside').style.marginLeft = "0px";
				}
	
				if (!$(this).next().hasClass("item")) {
					document.getElementById('view-inside').style.paddingLeft = "128px";
					$('.jcarousel-next').css('visibility', "hidden");
				} else {
					document.getElementById('view-inside').style.paddingLeft = "64px";
				}
		        $('#carousel-nav li').removeClass("active");
		        $('#carousel-nav li#nav_item_'+(carousel.first+1)).addClass("active");
				carousel.scroll(carousel.first+1);
	          }
          }
		return false;
		  
        });

        /*
         * Previous navigation button
         */
        $('#carousel-nav li.prev a').bind('click', function(){
            $('#item-view div.jcarousel-prev').trigger('click');
            return false;
        });
        $('#item-view div.jcarousel-prev').bind('click', function(){
          // We check the noBody var, to know if we have to ignore the second column
          if(noBody && (carousel.first==3)) {
            // Simulate a click on number 2
            $('a.nava_1').click();
          }
          else {
	          /* don't scroll backwards if there's no previous item */
	          if ($('#view-inside>li.jcarousel-item-'+(carousel.first-1)).is(":first"))
	          {
				 if(document.getElementById('view-inside')) {
				    if (carousel.first-1 == 1) {
						document.getElementById('view-inside').style.marginLeft = "-60px";
					} else {
						document.getElementById('view-inside').style.marginLeft = "0px";
					}
	
					document.getElementById('view-inside').style.paddingLeft = "64px";
					}
					$('.jcarousel-next').css('visibility', "visible");
			        $('#carousel-nav li').removeClass("active");
			        $('#carousel-nav li#nav_item_'+(carousel.first-1)).addClass("active");
		       }
	        }
	        });
       }});

       /* insert prev/next areas */
       $('#item-view div.jcarousel-next').append('<div class="hovered"><div class="nav-arrow"></div></div>')
       $('#item-view div.jcarousel-prev').append('<div class="hovered"><div class="nav-arrow"></div></div>')

      /* hover effect on previous/next */
      $('#item-view div.jcarousel-next, #item-view div.jcarousel-prev')
      .bind('mouseenter', function(){ $('div.hovered', this).fadeIn('normal'); })
      .bind('mouseleave', function(){ $('div.hovered', this).fadeOut('slow'); });

      /* fix png backgrounds at ie6 */
      $('#item-view div.jcarousel-next div.hovered, #item-view div.jcarousel-prev div.hovered').pngfix();

      /*
       * Flash movies
       */
      $('#movie1').flash({ src: '/movie/taste/taste-mov1.swf', width: 324, height: 327, wmode: 'transparent' });
      $('#movie2').flash({ src: '/movie/taste/taste-mov1.swf', width: 324, height: 327, wmode: 'transparent' });
    
          
      /*
       * Rating system
       */
      $('#rate_100').checkbox({cls:'jquery-radio-rate100', empty: VODKA.baseuri+'/images/pixel.gif'});
      $('#rate_75').checkbox({cls:'jquery-radio-rate75', empty: VODKA.baseuri+'/images/pixel.gif'});
      $('#rate_50').checkbox({cls:'jquery-radio-rate50', empty: VODKA.baseuri+'/images/pixel.gif'});
      $('#rate_25').checkbox({cls:'jquery-radio-rate25', empty: VODKA.baseuri+'/images/pixel.gif'});
      $('#rate_0').checkbox({cls:'jquery-radio-rate0', empty: VODKA.baseuri+'/images/pixel.gif'});
      $('#rate-content')
      .bind('mouseenter', function(){ 
        $(this).css({
          'height': '102px',
          'background-image': 'url("/images/buttons/rate.png")'
        });
        $('#input-wrapper', this)
          .show()
          .click(function(){
          $('#view-rating').fadeOut('slow');
          $.ajax({
           type: "POST",
           dataType: "html",
           url: VODKA.baseuri+"/content/rate",
           data: "contentId="+$('#content_id').val()+"&userId="+$('#user_id').val()+"&rating="+$('input[@type=radio][@checked]').val(),
           success: function(msg){
             $('#view-rating').html(msg).fadeIn('slow');
           }
          });
        });
      })
      .bind('mouseleave', function(){ 
        $(this).css('height', '17px');
        $(this).css('background-image', 'url("/images/buttons/rate-btn.png")');
        $('#input-wrapper', this).hide();
      });
      
      
      }

    /**
     * Encyclopedia
     */
    else if ($('#vodka-section').hasClass('encyclopedia'))
    {
      VODKA.initModal();

      /*
       * Change background
       */
      /*$('body').css('background', '#1f008a url("/images/sample/bgbar-ency.jpg") repeat-x');
      $('#background').css('background', 'url("/images/sample/bg-ency.jpg") no-repeat center top');
      $('#page').css('background', 'url("/images/sample/bgpt2.png") repeat');*/

      /*
       * Columns
       */
      var htmlContent = $('#encyclopedia-content').html();
      var columns = Columns.splitText(htmlContent, 287, 570);
      var columns_length = typeof columns == 'undefined' ? 0 : columns.length;

      //no columns ? No need to do all that
      if (!columns_length)
      {
        return;
      }

      /* count the carousel item index */
      var counter = 1;
      for (var i = 0; i < columns.length; i++)
      {
        $('#encyclopedia-inside').append('<li class="injected-column">'+columns[i]+'</li>');
        /* Check if the column contains a full-size image. If yes - put to its container an additional class which will increase its size */
        if (columns[i].indexOf('full-picture')!=-1)
        {
          $('#encyclopedia-inside li.injected-column:last').addClass('media-column').append();
          $('#media-thumbs').append('<li id="item-'+counter+'" class="thumbnail"><div class="cover"></div>'+columns[i]+'</li>');            
        }
        else if (columns[i].indexOf('full-movie')!=-1)
        {
           $('#encyclopedia-inside li.injected-column:last').addClass('media-column');
        }
        counter ++;
      }

      /* prev/next arrows */
      $('#media-thumbs').prepend('<li class="prev"><a href="#">Previous</a></li>');
      $('#media-thumbs').append('<li class="next"><a href="#">Next</a></li>');

      /* top list of thumbnails */
      $('#media-thumbs>li')
        .bind('mouseenter', function(){ $('.cover', this).fadeIn(); })
        .bind('mouseleave', function(){ $('.cover', this).fadeOut(); });

      /* fix png backgrounds at ie6 */
      $('#encyclopedia-inside li.injected-column span.legend, #media-thumbs>li>div.cover').pngfix();

      /*
       * Navigation
       */
       $('#encyclopedia-inside').jcarousel({ scroll: 1, animation: 'fast', initCallback: function(carousel){
        $('#media-thumbs li.thumbnail').bind('click', function() {
            var itemIndex = $(this).attr("id").split("-");
		  if(document.getElementById('encyclopedia-inside')) {
		 		if (itemIndex[1] == 1) {
					document.getElementById('encyclopedia-inside').style.marginLeft = "-60px";
				} else {
					document.getElementById('encyclopedia-inside').style.marginLeft = "0px";
				}
				document.getElementById('encyclopedia-inside').style.paddingLeft = "67px";
				$('.jcarousel-next').css('visibility', "visible");

				//document.getElementById('encyclopedia-inside').style.paddingLeft = "64px";

				if (!$(this).next().hasClass("thumbnail")) {
					document.getElementById('encyclopedia-inside').style.paddingLeft = "134px";
					$('.jcarousel-next').css('visibility', "hidden");
				}
            }
		  carousel.scroll($.jcarousel.intval(itemIndex[1]));
            return false;
        });

        $('#media-thumbs li.prev').bind('click', function() {
            if ($('#media-thumbs li').hasClass('thumb-active') && $('#media-thumbs li.thumb-active').prev().hasClass('thumbnail'))
            {
              /* if any of media thumbnails is already active and its 'thumbnail' predecessor does exist, scroll to the previous one */
              var itemIndex = $('#media-thumbs li.thumb-active').prev().attr("id").split("-");
              if(document.getElementById('encyclopedia-inside')) {
				    if (itemIndex[1] == 1) {
						document.getElementById('encyclopedia-inside').style.marginLeft = "-60px";
					} else {
						document.getElementById('encyclopedia-inside').style.marginLeft = "0px";
					}

					document.getElementById('encyclopedia-inside').style.paddingLeft = "67px";
			}
			$('.jcarousel-next').css('visibility', "visible");
              carousel.scroll($.jcarousel.intval(itemIndex[1]));
            }
            else 
            {
              /* if no media thumbnail is active, do notning */
              return false;
            }
            return false;
        });

        $('#media-thumbs li.next').bind('click', function() {
            if ($('#media-thumbs li').hasClass('thumb-active') && $('#media-thumbs li.thumb-active').next().hasClass('thumbnail'))
            {
              /* if any of media thumbnails is already active and its 'thumbnail' successor does exist, scroll to the next one*/
              var itemIndex = $('#media-thumbs li.thumb-active').next().attr("id").split("-");
		     carousel.scroll($.jcarousel.intval(itemIndex[1]));
		  if (itemIndex[1] == 1) {
				document.getElementById('encyclopedia-inside').style.marginLeft = "-60px";
			} else {
				document.getElementById('encyclopedia-inside').style.marginLeft = "0px";
			}

			if (!$('#media-thumbs li.thumb-active').next().next().next().html()) {
				document.getElementById('encyclopedia-inside').style.paddingLeft = "134px";
				$('.jcarousel-next').css('visibility', "hidden");
			} else {
				document.getElementById('encyclopedia-inside').style.paddingLeft = "67px";
			}
            }
            else 
            {
              /* if no media thumbnail is active, scroll to the first one */
              var itemIndex = $('#media-thumbs li.thumbnail:first').attr("id").split("-");
            }
           
            return false;
        });
       },
       itemFirstInCallback: function(carousel, li, index, state){
        // Commented to be conform to the mock-up=> if uncommented prevent the navigation from working
        //if ($(li).hasClass('media-column'))
        //{
          $('#media-thumbs>li').removeClass('thumb-active');
          $('#media-thumbs>li#item-'+index).addClass('thumb-active');
        //}
       } });
       
       
      /* Title links "anchor" : simulate a click on a thumb */
      $('ul.encylinks li a').each(function(){
      	var res = $(this).attr('class').match(/encylink-(\d)/);
      	if(res) {
      		$(this).click(function(){
      			$('#media-thumbs #item-'+res[1]).click();
      			return false;
      		});
      	}
      });
       

      /* insert prev/next areas */
      $('#encyclopedia-container div.jcarousel-next').append('<div class="hovered"><div class="nav-arrow"></div></div>')
      $('#encyclopedia-container div.jcarousel-prev').append('<div class="hovered"><div class="nav-arrow"></div></div>')
           
      /* hover effect on previous/next */
      $('#encyclopedia-container div.jcarousel-next, #encyclopedia-container div.jcarousel-prev')
      .bind('mouseenter', function(){ $('div.hovered', this).fadeIn('normal'); })
      .bind('mouseleave', function(){ $('div.hovered', this).fadeOut('slow'); });
      
      /* fix png backgrounds at ie6 */
      $('#encyclopedia-container div.jcarousel-next div.hovered, #encyclopedia-container div.jcarousel-prev div.hovered').pngfix();

	  /* LIGHTBOX ***********************************************/
	  
      /* assign all article media to lightbox */
      $('#encyclopedia-inside li.injected-column p.full-picture').each(function() {
        $(this).append('<a class="media-zoom" href="'+ $('img', this).attr('src') +'">Zoom</a>');
      });
      $('#encyclopedia-inside li.injected-column a.media-zoom').each(function(){
      	// We put a title to link : the one in the following p
      	if($(this).next('p').length > 0) {
      		$(this).attr('title',$(this).next('p').html());
      	}
      	else {
	      	if($(this).prev('p').length > 0) {
	      		$(this).attr('title',$(this).prev('p').html());
	      	}
      	}
      });
      $('#encyclopedia-inside li.injected-column a.media-zoom').lightBox({
      	fixedNavigation:true,
      	containerBorderSize:'0'
      	/*imageLoading:'images/ZoomLoad.gif'*/
      });
      /**********************************************************/

      /* Legend on images */
      $('#encyclopedia-inside li.injected-column p.full-picture').each(function() {
        if ($('img', this).attr('alt')) {
          /*alert($('img', this).attr('alt'));*/
          $(this).append('<span class="legend">' + $('img', this).attr('alt') + '</span>');
        }
      });

      /*
       * Snippets
       */
      $('#snippet > ul').jcarousel({ scroll: 1, animation: 'fast' });

      /* foreach movie don't forget to add its width to the ul#encyclopedia-inside  */
      //$('#encyclopedia-inside').width($('#encyclopedia-inside').width() + $('#movie1').width());
    }

    /**
     * Registration
     */
    else if ($('#vodka-section').hasClass('registration'))
    {
      VODKA.initModal();
      
      $('#registration input:checkbox').checkbox({empty: VODKA.baseuri+'/images/pixel.gif'});
      $('#registration input:radio').checkbox({cls:'jquery-radio', empty: VODKA.baseuri+'/images/pixel.gif'});
      
    }

    /*
     * Apply PNG fix for IE 7 below
     * - img which are explicitely translucent
     * - main areas of navigation
     * - all section map area
     */
    if ($.browser.msie && parseInt($.browser.version) < 7)
    {
      $('img.translucent[src$=png]').pngfix();
      $('#navigation-content, #user-actions, #website-links').pngfix();
      $('#section-map > li.content-box, #section-map ul.items a > span').pngfix();
      $('#grid-container li.box h3, #grid-container li.box > div.info, #grid-container li.box span.rating-number ').pngfix();
      $('#registration div.registration-fields-inside, #registration div.submit-area').pngfix();
    }
  };
  //end of VODKA.init()
  
  /**
   * Process hovering with scale
   * @param {Object} a
   */
  VODKA.processHovering = function(aObject,currentSection){  
  	//aObject.effect('scale',{percent:150,origin:'center'},1);
        
    oldWidth = aObject.width();
    oldHeight = aObject.height();
    
    newWidth = currentSection.width;
    newHeight = currentSection.height;
    
    /*newWidth = parseInt(oldWidth * 150 / 100);
    newHeight = parseInt(oldHeight * 150 / 100);*/
    
  	// We close everythings !
    /*$('#side-section-map>li>ul.items').each(function(){
    	VODKA.cancelHovering($('a.title-on', this));
    });*/
    
    
    if(newWidth != oldWidth && newHeight != oldHeight) {
	    aObject.width(newWidth);
	    aObject.height(newHeight);
	    aObject.css('left',parseInt((oldWidth - newWidth)/2));
	    aObject.css('top',parseInt((oldHeight - newHeight)/2));
	    
	    // We create a new span inside link, to manage the mouse leave...
	    newWidth = newWidth + 1;
	    newHeight = newHeight + 1;
	    spanElement = document.createElement("span");
	    $(spanElement).attr('class','mouseleave');
	    $(spanElement).css('width',oldWidth);
	    $(spanElement).css('height',oldHeight);
	    $(spanElement).css('top',parseInt((newHeight - oldHeight)/2));
	    $(spanElement).css('left',parseInt((newWidth - oldWidth)/2));
	    
	    //var liObject = aObject;
	    
	    $(spanElement).bind('mouseleave', function(){
	    	liObject = $(this).parents('li:first');
	    	
		    if(!$(liObject).hasClass('coming-soon')) {
		      aObject = $('a.title-on', liObject);
		      $('a:first', liObject).show();
		      aObject.hide();
		      //$('a.title-on', $('#side-section-map>li>ul.items>li.item-active')).show();
		      
		      //liObject.style.overflow = 'hidden';
		      //$(liObject).style.overflow = 'hidden';
		      liObject.css('overflow','hidden');
		      
		      $('ul#side-section-map').css('overflow','hidden');
		      $('ul#side-section-map ul').css('overflow','hidden');
		      
		      $('#side-section-map>li>ul.items>li').css('z-index','1');
		      
		      VODKA.cancelHovering(aObject);
	         }
	     });
	    
	    aObject.append(spanElement);
    }
    
    aObject.addClass('hovered');
  }
  
  /**
   * Process hovering with scale
   * @param {Object} a
   */
  VODKA.cancelHovering = function(aObject){  	
  	//aObject.effect('scale',{percent:50,origin:'center'},10);
  	
  	aObject.removeClass('hovered');
  
    /*oldWidth = aObject.width();
    oldHeight = aObject.height();
    newWidth = oldWidth * 100 / 150;
    newHeight = oldHeight * 100 / 150;
    
    aObject.width(newWidth);
    aObject.height(newHeight);
    
    aObject.css('left',0);
    aObject.css('top',0);*/
    //$('embed', aObject).width('100%');
    //$('embed', aObject).height('100%');
    
    //$('img', aObject).width('100%');
    //$('img', aObject).height('100%');
  }

  /**
   * 
   * @param {Object} $to
   * @param {Object} href
   * @param {Object} hash
   */
  VODKA.ajaxStart = function($to, href, hash){
    /*console.log($to);
    console.log(href);
    console.log(hash);*/
    
    // Sepcial case for terms and social responsability and register, because this pages can be seen without to be connected
    if(hash=='terms-and-conditions' || hash=='social-responsability' || hash=='user/register') {
    	window.location = VODKA.baseuri + '/' + hash;
    	return false;
    }
    
    // When the ajax navigation is going to be broken, self.location.pathname is more than /
    // It have to be only /    
    if(self.location.pathname != '/') {
    	// we redirect with right url loading all page
    	// we don't put # if it's welcome page
    	if(self.location.pathname == '/welcome')
    		window.location = VODKA.baseuri;
    	else
    		window.location = VODKA.baseuri + '/#' + hash;
    	return false;
    }
  };

  /**
   * 
   * @param {Object} $to
   * @param {Object} href
   * @param {Object} hash
   * @param {Object} data
   */
  VODKA.ajaxExecution = function($to, href, hash, data){
    //Check if we get data from the required url => if not redirect on the site home
    //Also check 
    if (data == '' || data.match(/welcome-box/)) {window.location = VODKA.baseuri;return false;};
    
    /*
     * Fading out some elements
     */
     $('#page #website-logo img, #page #content').fadeOut(400, function(){
      $(this).empty();
    });
     
    setTimeout(function(){
      // Test Temporary div in current DOM : should already exists (put on homepage template)
      if(!$('#vodka-ajax-temp')) {
      	$('body').append('<div id="vodka-ajax-temp"></div>');
      }
      else {
      	// clear its content
      	$('#vodka-ajax-temp').empty();
      }
     
      // We put data inside it : just body element
      data2 = data;
      data2 = data2.replace(/\r/gi,String.fromCharCode(17));
      data2 = data2.replace(/\n/gi,String.fromCharCode(18));
      var bodyArray = data2.match(/<body[^>]*?>(.*)<\/body>/i);
      
      var body = bodyArray[1];
      
      // no javascript tag
      //var bodyTemp = body.replace(/<script.*?<\/script>/gi,'');
      var bodyTemp = body;
      
      var reg1 = new RegExp(String.fromCharCode(17), "gi");
      var reg2 = new RegExp(String.fromCharCode(18), "gi");		
	  bodyTemp = bodyTemp.replace(reg1,"\r");
	  bodyTemp = bodyTemp.replace(reg2,"\n");

      // Actually, we only must take the div id="page" content
      // so lets change this id
      $('#vodka-ajax-temp').html(bodyTemp);
      $('#vodka-ajax-temp #page').attr('id','pageAjax');
      
      /*
       * Updating section classname
       * Updating easing/modal containers (mandatory to refresh events)
       * Updating page title
       */
        	
      $('#page #vodka-section').attr('className', $('#vodka-ajax-temp #vodka-section').attr('className'));
      $('#page #easing-wrapper').replaceWith($('#vodka-ajax-temp #easing-wrapper'));
      
      // Title : don't use the same way
      var titleTemp = data.match(/(<title>.*<\/title>)/i);
      $('title').replaceWith(titleTemp[1]);
      
      /*
       * Website background (fading)
       */
      
      // New way
      // the section information is in <div id="website-background">
      var currentSection = $('#vodka-ajax-temp #website-background').html();
      
      // update
      if($('#page #website-background').html() != currentSection) {
	      $('#page #website-background').html(currentSection);
	      switch(currentSection) {
			case 'home' :
			case 'default' :
			case 'news' :
			case 'live' :
				$('html').css('backgroundImage', 'url("/images/logos_bg/bg-hp_grad.jpg")');
				$('html').css('backgroundColor', '#5e5e5e');
	     		$('body').css('backgroundImage', 'url("/images/logos_bg/bg-hp.jpg")');
				break;
			case 'myth' : 
				$('html').css('backgroundImage', 'url("/images/logos_bg/bg-ency_grad.jpg")');
				$('html').css('backgroundColor', '#270283');
	      		$('body').css('backgroundImage', 'url("/images/logos_bg/bg-ency.jpg")');
				break;
			case 'vodkapedia' :
				$('html').css('backgroundImage', 'url("/images/logos_bg/bg-brand_grad.jpg")');
				$('html').css('backgroundColor', '#08020e');
      			$('body').css('backgroundImage', 'url("/images/logos_bg/bg-brand.jpg")');
	      		break;
			case 'kulture' :
				$('html').css('backgroundImage', 'url("/images/logos_bg/bg-fame_grad.jpg")');
				$('html').css('backgroundColor', '#010e17');
	      		$('body').css('backgroundImage', 'url("/images/logos_bg/bg-fame.jpg")');
				break;
			case 'taste' :
				$('html').css('backgroundImage', 'url("/images/logos_bg/bg-mix_grad.jpg")');
				$('html').css('backgroundColor', '#1c211d');
	      		$('body').css('backgroundImage', 'url("/images/logos_bg/bg-mix.jpg")');
				break;
			default :
				$('html').css('backgroundImage', 'url("/images/logos_bg/bg-hp_grad.jpg")');
				$('html').css('backgroundColor', '#5e5e5e');
	     		$('body').css('backgroundImage', 'url("/images/logos_bg/bg-hp.jpg")');
		  }
	  }
	  
      /*
       * Website logo (fading)
       */
      //$('#page #website-logo img').replaceWith($('#website-logo img', data));
      //$('#page #website-logo img').replaceWith($('#vodka-ajax-temp #website-logo img'));
      
      /*
       * Website content (fading)
       */
      $('#page #content').replaceWith($('#vodka-ajax-temp #content'));
      
      /*
       * Content Tools
       */
      var $content_header = $('#page #content-header');
      var $content_header_dist = $('#vodka-ajax-temp #content-header');
      
      if ($content_header.length)
      {
        //current and future
        if ($content_header_dist.length)
        {
          $content_header.replaceWith($content_header_dist);
        }
        //current but no future
        else{
          $content_header.remove();
        }
      }
      //no current but future
      else if ($content_header_dist.length)
      {
        $('#page #content').before($content_header_dist);
      }

      /*
       * User bar
       */
      $('#page #user-actions').replaceWith($('#vodka-ajax-temp #user-actions'));

      /*
       * Navigation
       */
      $('#page #navigation').replaceWith($('#vodka-ajax-temp #navigation'));
      
      // Empty now
      $('#vodka-ajax-temp').empty();

      /*
       * FadeIn
       */
      VODKA.ajaxComplete();
      $('#page #website-logo img, #page #content').fadeIn('normal');
    }, 400);
  
	var pageTracker = _gat._getTracker(siteID);
	if (hash!='') {
		pageTracker._trackPageview('/'+hash);
	}
	else {
		pageTracker._trackPageview();
	}
  };

  /**
   * 
   * @param {Object} $to
   * @param {Object} href
   * @param {Object} hash
   */
  VODKA.ajaxComplete = function($to, href, hash){
    //VODKA.initGridBox();
    
    //CSBfleXcroll('grid-container');
    fleXenv.initialized = false;
    fleXenv.globalInit();
    //CSBfleXcroll('nav-news');
    
    VODKA.init();
    VODKA.postInit(); //uncomment if jcarousel is unpatched
  };

  /**
   * 
   */
  VODKA.initGridBox = function(){
    var ol_width = $('#grid-container ol > li.column').attr('offsetWidth') * ($('#grid-container ol > li.column').length);
    $('#grid-container ol.grid-box').width(ol_width);
    
    // If pagination, consider each arrow width
    if($('#left-grid-nav-arrow-main').length) {
    	ol_width += 70;
    }
    if($('#right-grid-nav-arrow-main').length) {
    	ol_width += 67;
    }
    $('div#grid-main').width(ol_width);
    
    /* hover effect on previous/next */
    $('#left-grid-nav-arrow-main, #right-grid-nav-arrow-main')
      .bind('mouseenter', function(){ $('div.grid-hovered', this).addClass('red-bg'); })
      .bind('mouseleave', function(){ $('div.grid-hovered', this).removeClass('red-bg'); });

    $('#grid-container ol li.box')
      .bind('mouseleave', function(){ $('div.info', this).hide(); })
      .bind('mouseleave', function() {$(this).removeClass("whiteBorder");})
      .bind('click', function() {$('h3 a', this).trigger('click');})
      .bind('mouseenter', function() {$(this).addClass("whiteBorder");})
      .bind('mouseenter', function(){ $('div.info', this).show(); });
      
    CSBfleXcroll('grid-container');
  };
  
  
  /* Use for display thickbox terms and social */
  VODKA.processContentBox = function(h) {
  	// add close link
  	h.w.prepend('<a class="jqmClose"></a>');
  }
  

  /**
   * 
   */
  VODKA.initModal = function(){
    $('#content-permalink').jqm({ajax: '@href', trigger: '#content p.stats a.permalink'});
    $('#content-send').jqm({ajax: '@href', trigger: '#content p.stats a.send'});
    /*$('#disclaimer').jqm({ajax: '@href', trigger: 'a.disclaimer', modal: true});*/
    /*$('#disclaimer').jqm({ajax: '@href', trigger: 'a.disclaimer', modal: true, onHide: function(h) {h.o.hide();h.w.remove();}});*/
    $('#disclaimer').jqm({ajax: '@href', trigger: 'a.disclaimer', modal: true, onHide: function(h) {h.o.hide();VODKA.removeDisclaimer();}});
    $('#contactbox').jqm({ajax: '@href', trigger: 'a.contactbox, a.title-on-contact, a.title-contact'});
    
    /* Thickbox for terms and social */
    // Careful : this don't work for disclaimer
    // so the same line is in disclaimer index
    if($('a#terms-box').length>0) {
    	$('#content-terms-box').jqm({ajax: '@href', trigger: 'a#terms-box', onLoad:function(h){VODKA.processContentBox(h);CSBfleXcroll('div-terms-conditions');}});
    }
    // this should not be used
    if($('a#social-box').length>0) {
    	$('#content-social-box').jqm({ajax: '@href', trigger: 'a#social-box', onLoad:function(h){VODKA.processContentBox(h)}});
    }
    
    /* Thickbox register form in welcome : have to be here */
    $('#content-welcome-register-box').jqm({ajax: '@href', trigger: 'a#welcome-register-box', onLoad:function(h){VODKA.processContentBox(h);}});
  };

  /**
   * 
   */
  VODKA.postInit = function(){
    //remove jCarousel bind events (on window resize)
    $(window).unbind('resize');
    VODKA.initModal();
    VODKA.disclaimer();
    VODKA.initLoginbox();
    VODKA.initLibrarybox();
  };

  /**
   * 
   */
  VODKA.initLoginbox = function(){
    $('#login-box input:checkbox').checkbox({
      empty: VODKA.baseuri + '/images/pixel.gif'
    });
    $('li.login').toggle(function(){
      $('#login-box').show();
      $('#user-actions li.login').height(25);
      $('#user-actions li.login').css('background', 'url(/images/buttons/loginbox.png) no-repeat 0 -15px');
    }, function(){
      $('#login-box').hide();
      $('#user-actions li.login').height(15);
      $('#user-actions li.login').css('background', 'url(/images/buttons/login.png) no-repeat 0 0');
    })
  };

  /**
   * 
   */
  VODKA.initLibrarybox = function(){
    $('span.links span a.add-to-favourite').click(function(){
      $('#library-box').html("<p><i>Added in your library</i></p>");
      $('#library-box').show();
      $('#library-box').fadeOut(4000);
    });
    $('span.links span a.favourite').click(function(){
      $('#library-box').html("<p><i>Removed from your library</i></p>");
      $('#library-box').show();
      $('#library-box').fadeOut(4000);
    });
  };

  /**
   * 
   */
  VODKA.disclaimer = function(){
    if ($('#disclaimer'))
    {
      //$('a.disclaimer').click().hide();
      $('a.disclaimer').click();
      var top = $(window).height()/2 - 100;
      $('#disclaimer').css('top', top);
    }
  };

  /**
   * 
   * @param {Object} className
   */
  VODKA.switchGridBox = function(className){
    /*
     * Switching active content
     */
    $("#grid-switch li")
      .removeClass("active")
      .filter('.'+className).addClass("active");

    /*
     * Reiniting grid box
     */
     VODKA.initGridBox();
     
    /*
     * Enabling Flexcroll only for this part
     */
     //CSBfleXcroll('grid-container');
  };
  
  /*
   * Remove the disclaimer as soon as it have been entered 
   */
  VODKA.removeDisclaimer = function() {
  	/*$('#disclaimer').jqm.close();*/
  	$(".disclaimer").remove();
  	$("#disclaimer").remove();
  };
  

  /**
   * Global init
   */
  $(VODKA.init);
  $(VODKA.postInit);
})(jQuery);