function prepare_for_mac()
{
	if(navigator.platform.indexOf("Mac") != -1 || navigator.userAgent.indexOf("Safari") != -1)
	{
		document.body.className += ( navigator.userAgent.indexOf("Safari") != -1 ? ' mac safari' : ' mac firefox' );
	}
}
function init_language_selection()
{
	$(".language_selection .select").click(function()
	{
		var newDisplay	= ( $(".language_selection .dropdown").css('display') == 'none' ? 'block' : 'none' );
		$(".language_selection .dropdown").css('display',newDisplay);
	});
	$(".language_selection .dropdown .language").each(function(i)
	{
		$(this).hover(
			function() { $(this).addClass("hover"); },
			function() { $(this).removeClass("hover"); }
		)
		.click(function()
		{
			window.location.href	= $(this).find('a').attr('href');
		});
	});
}
function position_items()
{
	// The footer
	var winHeight		= $(window).height();
	var wrapperHeight	= $('#wrapper').height();
	var footerHeight	= $('#footer').height() + parseInt($('#footer').css('paddingTop'));
	if(winHeight > (wrapperHeight + footerHeight))
	{
		$('#wrapper').height(winHeight-footerHeight);
	}
	$('#footer').css('display','block');

	// The vertical HR on download_page
	$('.vertical_hr').css('height',$('#page').height());
}
function show_thumb()
{
	var data = $(this).find('.hidden').html().replace('<!--[CDATA[', '').replace(']]-->', '');
	json = eval(data);
	
	$ex = $('.exhibition');
	$ex.find('.image').html(json.image);
	$ex.find('.content').html(json.content);
	window.scrollTo(0,0);
}
function show_ecard()
{
	var data = $(this).find('.hidden').html().replace('<!--[CDATA[', '').replace(']]-->', '');
	json = eval(data);
	
	$ex = $('.exhibition');
	$ex.find('.image').html(json.image);
	$('.infoarea').find('input[name="id"]').val(json.id);
}
function show_brand()
{
	var $this	= $(this);
	var data 	= $this.find('.hidden').html().replace('<!--[CDATA[', '').replace(']]-->', '');
	json		= eval(data);

	$this.parent().find('.active').removeClass('active');
	$this.addClass('active');
	$('#page').css('background-image','url('+json.image+')');
	$('.overlay').html(json.content);
	$('.brandinfo').html(json.brandinfo);
}
function show_video()
{
	var $ex 	= $('.exhibition');
	var $this	= $(this);
	var data 	= $this.parent().find('.hidden').html().replace('<!--[CDATA[', '').replace(']]-->', '');
	json		= eval(data);

	myFlashObject.changeSource(json.video);

	$ex.find('.content').html(json.content);
}
function show_year(id)
{
	var $ex 	= $('.exhibition');
	var data 	= $('#year_'+id).html().replace('<!--[CDATA[', '').replace(']]-->', '');
	json		= eval(data);

	$ex.find('.content').html(json.content);
	$image	= $ex.find('.image');

	if(json.panorama !== false)
	{
		$image.html('<div id="panorama"></div>');
		var panoramaObject	= {};

		var params			= {};
		params.menu			= 'false';
		params.wmode		= 'transparent';
		params.flashvars	= 'imageURL='+json.panorama;

		var attributes		= {};
		attributes.id		= 'panorama_flash';
		attributes.data		= global_url + 'image/panorama.swf';
		attributes.width	= 640;
		attributes.height	= 395;

		panoramaObject = swfobject.createSWF(attributes, params, 'panorama');
	}
	else
	{
		$image.html(json.image);	
	}
}
function show_product_information()
{
	$('.exhibition .content .link_desc').addClass('hidden');
	$('.exhibition .content .description').addClass('hidden');
	$('.exhibition .content .information').removeClass('hidden');
	$('.exhibition .content .link_info').removeClass('hidden');
}
function show_product_description()
{
	$('.exhibition .content .information').addClass('hidden');
	$('.exhibition .content .link_info').addClass('hidden');
	$('.exhibition .content .link_desc').removeClass('hidden');
	$('.exhibition .content .description').removeClass('hidden');
}
function product_prev()
{
	pObject.showBottle(1);
}
function product_next()
{
	pObject.showBottle(2);
}

var currentProductIndex = 0; 

function show_product(id, from_flash)
{
	var $productData 	= $('#product_'+id);
	var index 			= $('.product_data').index($productData);
	
	$('.jcarousel-control a').removeClass('active').eq(index).addClass('active');
	
	if (!from_flash && pObject)
	{
		if (currentProductIndex == 2 && index == 0) product_prev();
		else if (currentProductIndex == 0 && index == 2) product_next();
		else if (index > currentProductIndex) product_prev();
		else if (index < currentProductIndex) product_next();
		else return;
	}

	var $desc			= $('.exhibition .content .description');
	var $info			= $('.exhibition .content .information');
	var $availability	= $('.exhibition .content .link_popup');
	var $footnote		= $('.exhibition .footnote');

	var data 	= $productData.html().replace('<!--[CDATA[', '').replace(']]-->', '');
	json		= eval(data);

	$('.exhibition .content .link_desc').removeClass('hidden');
	$('.exhibition .content .link_info').addClass('hidden');

	if(json.availability == 'true')
	{
		$availability.show();
		
		$availability.get(0).onclick = function()
		{
			show_product_avaliability(id);	
		}
	}
	else
	{
		$availability.hide();	
	}

	$desc.html(json.description);
	$info.html(json.information);
	$footnote.html(json.footnote);

	$desc.removeClass('hidden');
	$info.addClass('hidden');
	
	currentProductIndex = index;
}
function popup(url,id,width,height,scroll) 
{
	pos_horizon = ((screen.width/2)-(width/2));
	pos_vertical = ((screen.height/2)-(height/2));
	scroll = scroll || 'no';
	var popup_win = window.open(url,id,'width='+width+',height='+height+',left='+pos_horizon+',top='+pos_vertical+',resizable=no,scrollbars='+scroll+',menubar=no,status=no');
	return popup_win;
}
function show_product_avaliability(product_id)
{
	var win	= popup(global_url + 'popup.product.php?lang='+lang+'&id='+product_id, product_id, 831, 551);
}
function show_teaser(teaser_id)
{
	var win	= popup(global_url + 'popup.teaser.php?lang='+lang+'&id='+teaser_id, teaser_id, 831, 551);
}
function show_privacy()
{
	var win	= popup(global_url + 'popup.privacy.php?lang='+lang, null, 990, 551, 'yes');
}
function show_contact_list(page_id)
{
	var win	= popup(global_url + 'popup.worldmap.php?lang='+lang+'&id='+page_id, page_id, 831, 551);
}
function checkEmail(email)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,6})+$/.test(email))
	{
		return true;
	}
	return false;
}

function setcookie(name, value, expires, path, domain, secure) 
{
    // http://kevin.vanzonneveld.net
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // *     example 1: setcookie('author_name', 'Kevin van Zonneveld');
    // *     returns 1: true
 
    expires instanceof Date ? expires = expires.toGMTString() : typeof(expires) == 'number' && (expires = (new Date(+(new Date) + expires * 1e3)).toGMTString());
    var r = [name + "=" + escape(value)], s, i;
    for(i in s = {expires: expires, path: path, domain: domain}){
        s[i] && r.push(i + "=" + s[i]);
    }
    return secure && r.push("secure"), document.cookie = r.join(";"), true;
}

function getcookie(c_name)
{
	if (document.cookie.length > 0)
	{
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1)
		{ 
			c_start = c_start + c_name.length+1; 
			c_end	= document.cookie.indexOf(";", c_start);

			if (c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start, c_end));
		} 
	}
	return "";
}

// Add onLoads
jQuery(document).ready(function()
{
	prepare_for_mac();
	init_language_selection();
	position_items();
});
$(function(){$(document).pngFix({blankgif: global_url + 'image/blank.gif'});});




// Sergey
/*
 Global JS
*/
$(document).ready(function() {

    // Toggle the Langs popup
    $('#control-country .select').click(
      function(){
        $('#control-country .select').addClass('clicked');
        $('.lang-dialog').show();
        $('.lang-page-select').show(); 
      }
    );
    
    $('.lang-page-select').click(
      function(){
        $('#control-country .select').removeClass('clicked');
        $('.lang-dialog').hide();
        $('.lang-dialog .share-page-select').hide(); 
      }
    );    

  /* if (!swfobject.hasFlashPlayerVersion('6.0.65'))
  {
    location.href='http://orangina.eu/errors/flash/';
  } */
  
  // Popup
  function addEvent(elm, evType, fn, useCapture){if(elm.addEventListener){elm.addEventListener(evType, fn, useCapture);return true;}else if (elm.attachEvent){var r = elm.attachEvent('on' + evType, fn);return r;}else{elm['on' + evType] = fn;}}
      var newWindow = null;

      function closeWin(){
        if (newWindow != null){
          if(!newWindow.closed)
            newWindow.close();
        }
      }

      function popUpWin(url, type, strWidth, strHeight){

        closeWin();

        type = type.toLowerCase();

        if (type == "fullscreen"){
          strWidth = screen.availWidth;
          strHeight = screen.availHeight;
        }
        var tools="";
        if (type == "standard") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
        if (type == "console" || type == "fullscreen") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
        newWindow = window.open(url, "newWin", tools);
        newWindow.focus();
      }

      function doPopUp(e)
      {
      //set defaults - if nothing in rel attrib, these will be used
      var t = "standard";
      var w = "800";
      var h = "550";
      //look for parameters
      attribs = this.rel.split(" ");
      if (attribs[1]!=null) {t = attribs[1];}
      if (attribs[2]!=null) {w = attribs[2];}
      if (attribs[3]!=null) {h = attribs[3];}
      //call the popup script
      popUpWin(this.href,t,w,h);
      //cancel the default link action if pop-up activated
      if (window.event) 
        {
        window.event.returnValue = false;
        window.event.cancelBubble = true;
        } 
      else if (e) 
        {
        e.stopPropagation();
        e.preventDefault();
        }
      }

      function findPopUps()
      {
      var popups = document.getElementsByTagName("a");
      for (i=0;i<popups.length;i++)
        {
        if (popups[i].rel.indexOf("popup")!=-1)
          {
          // attach popup behaviour
          popups[i].onclick = doPopUp;
          }
        }
      }

      addEvent(window, "load", findPopUps, false);
    
    $("#carousel a").each(function() {
        if(this.href == window.location.href.split("#")[0]) {
      $(this).addClass("active");
            $("#carousel a.active").click(function() { return false; });
    }
    });

  
});