$(function()
{
	$('#splashcontent a').bind('click',function(){
		$.cookie('mares_region', this.href.substring(this.href.length-2), { expires: 365});
	});
	
	$('.btn_zoom').bind('click',function()
	{
		image_stack = '';
		image_active = '';
		$('#product_image_large img').each(function()
		{
			if ($(this).parent().css('display') != 'none')
			{
				image_active = $(this).attr('src').replace('/detail/', '/zoom/');
			}
			image_stack = image_stack + $(this).attr('src').replace('/detail/', '/zoom/') + ';';
		});
		
		swf_width = $('#product_images').width();
		swf_height = $('#product_images').height();

		swf_width = swf_width + 30;
		swf_height = swf_height + 12;
		
		stamp = new Date().getTime()
		
		var flashvars =
		{
			project: c_project, region: c_region, language: c_language, image_stack: image_stack, image_active: image_active };
		var params =
		{
			menu: 'false', scale: 'noscale', salign: 'tl', wmode: 'window', bgcolor: '#FFFFFF', allowfullscreen: 'true'
		};
		swfobject.embedSWF(c_swf_url + 'zoom.swf?rnd=' + stamp, 'zoom_swf', swf_width, swf_height, '9.0.0', 'expressInstall.swf', flashvars, params);
		
		var offset = $('.detail_img_and_desc').offset();
		$('#zoom').css({left: offset.left, top: offset.top});
		$('#zoom').show();

		return false;
	});
	
	if ( $(".tech_content").length > 0 )
	{
		if (location.hash.substr(0,9) == '#overlay_')
		{
			$(location.hash + '_trigger').trigger('click');
		}
	}
	
	//alert(location.hash);
	
	$('.async_promotion').each(function()
	{
		id = $(this).attr('id').split('_');
		var obj = $(this);
		
		$.ajax
		({
		  url: c_api_url + 'promotion/' + c_project + '/' + c_region + '/' + id[1] + '.html',
		  success: function(data)
		  {
		  	  obj.html(data);
		  }
		});
	});
	
});

$(window).resize(function()
{
	if ( $("#zoom").css('display') == 'block')
	{
		var offset = $('.detail_img_and_desc').offset();
		$('#zoom').css({left: offset.left, top: offset.top});
	}
});

function newsletter(region)
{
	switch(region)
	{
		case 'it':
			url = 'https://login.emarsys.net/u/register.php?CID=125088442&f=143';
			break;
		case 'fr':
			url = 'https://login.emarsys.net/u/register.php?CID=110275157&f=238';
			break;
		case 'us':
			url = 'https://login.emarsys.net/u/register.php?CID=129137220&f=125';
			break
		case 'de':
			url = 'https://login.emarsys.net/u/register.php?CID=119230380&f=210';
			break;
		case 'es':
			url = 'https://login.emarsys.net/u/register.php?CID=113070500&f=230';
			break;
		case 'nl':
			url = 'https://login.emarsys.net/u/register.php?CID=111088459&f=185';
			break;
		default:
			url = 'https://login.emarsys.net/u/register.php?CID=124297396&f=170';
	}
	window.open(url, 'newsletter', 'width=700,height=620,scrollbars=yes,statusbar=yes');
}

function newsletter_alt(region)
{
	switch(region)
	{
		case 'it':
			url = 'https://login.emarsys.net/u/register.php?CID=125088442&f=145';
			break;
		case 'fr':
			url = 'https://login.emarsys.net/u/register.php?CID=110275157&f=236';
			break;
		case 'us':
			url = 'https://login.emarsys.net/u/register.php?CID=129137220&f=123';
			break
		case 'de':
			url = 'https://login.emarsys.net/u/register.php?CID=119230380&f=208';
			break;
		case 'es':
			url = 'https://login.emarsys.net/u/register.php?CID=113070500&f=228';
			break;
		case 'nl':
			url = 'https://login.emarsys.net/u/register.php?CID=111088459&f=187';
			break;
		default:
			url = 'https://login.emarsys.net/u/register.php?CID=124297396&f=172';
	}
	
	window.open(url, 'newsletter', 'width=700,height=620,scrollbars=yes,statusbar=yes');
}

function product_registration()
{
	url = 'http://oms.mares.com/cpr/';
	window.open(url, 'product_registration', 'width=800,height=600,scrollbars=yes,statusbar=yes');
}

function gotoProduct(uid)
{
	location.href = c_home + 'products/?region=' + c_region + '&uid=' + uid;
}

function closeZoom()
{
	$('#zoom').hide();
}

