function BuyOnline()
{
	location.href = '../find/dealers.php?region=' + c_region;
}

function DealerSubmit(selector)
{
	if (selector.name == 'country')
	{
		if (document.forms['dealer_rental_locator'].state)
		{
			document.forms['dealer_rental_locator'].state.value='';
		}
	}
	if (selector.name == 'state' || selector.name == 'country')
	{
		if (document.forms['dealer_rental_locator'].city)
		{
			document.forms['dealer_rental_locator'].city.value='';
		}
	}
	document.forms['dealer_rental_locator'].submit();
}

$(function(){

	gray = {
		body_height: document.documentElement.clientHeight || $('body').height(),
	
		show: function(){
			this.gray ? this.unhide() : this.build();
		},
		
		build: function(){
			this.initialize_layout();
			this.unhide();
		},
		
		initialize_layout: function(){
			$('body').append('<div id="gray"></div><div id="mediacenter"></div>');
			this.gray = $('#gray').css({width:$(document).width()+'px',height:$(document).height()+'px'});
			this.mediacenter = $('#gray').css({width:$(document).width()+'px',height:$(document).height()+'px'});
		},

		hide: function(){
			$('#mediacenter').hide();
			$('#gray').hide();
			showAllByTag('embed');
			showAllByTag('object');
		},
		
		unhide: function(){
			$('#gray').show();
			$('#mediacenter').show();
			hideAllByTag('embed');
			hideAllByTag('object');
		},
		
		resize: function(){
			this.body_height = document.documentElement.clientHeight || $('body').height();
			this.height = Math.min((this.is_board?600:this.max_height),this.body_height);
			this.gray.css({height:$(document).height()+'px', width:(document.documentElement.clientWidth || $('body').width())+'px'});
		}
	};
	
	$(window).resize(function(){
		if ( $("#gray").length > 0 ){
			gray.resize();
		}
	});
	
});


$(function(){
	//display team image
	$('#additional_information>.multimedia_links li').bind('click',function(){
		$('#team_image_large').attr('src',$('img.web',this)[0].src);
		$('#additional_information>.multimedia_links>li.active').removeClass('active');
		$(this).addClass('active');
	});

});

$(function(){
	//save region choice
	$('.language_selection a').bind('click',function(){
		$.cookie('ridehead_region', this.href.substring(this.href.length-2), { expires: 365});
	});

});

function MediaCenterInit(id, category, keyword)
{
	var so_mc = new SWFObject('http://www.head.com/mediacenter/MediaCenter.swf', 'swf_mediacenter', '1125', '750', '9', '#000000');
	so_mc.addParam('loop', 'false');
	so_mc.addParam('menu', 'false');
	so_mc.addParam('scale', 'noscale');
	so_mc.addParam('salign', 'tl');
	so_mc.addParam('wmode', 'window');
	so_mc.addParam('allowfullscreen', 'true');
	so_mc.addParam('allowscriptaccess', 'always');
	so_mc.addParam('allownetworking', 'all');
	so_mc.addParam('bgcolor', '1a1a1a');

	so_mc.addVariable('mightyframedock', 'http://www.head.com/_swf/index.php');
	so_mc.addVariable('project', c_project);
	so_mc.addVariable('region', c_region);
	so_mc.addVariable('language', c_language);
	so_mc.addVariable('variant', c_variant);
	so_mc.addVariable('tag', 'snowboard');
	so_mc.addVariable('config', 'http://www.head.com/mediacenter/ridehead_config_live.xml');
	so_mc.addVariable("details", id);
	so_mc.addVariable("category", category);
	so_mc.addVariable("keyword", keyword);
	so_mc.setAttribute("style", ';');
	so_mc.write("mediacenter");
}

function MediaCenter()
{
	MediaCenterLoad('', '', '');
}

function MediaCenterPlay(id)
{
	MediaCenterLoad(id, '', '');
}

function MediaCenterOpen(id, category)
{
	MediaCenterLoad(id, category, '');
}

function MediaCenterSearch(id, category, keyword)
{
	MediaCenterLoad(id, category, keyword);
}

function MediaCenterLoad(id, category, keyword)
{
	$(function(){gray.show();});
	MediaCenterInit(id, category, keyword)
}

function MediaCenterClose()
{
	$(function(){gray.hide();});
}

function MediaCenterShutDown()
{
	media_center_is_open = false;
	SWFAddress.setValue('/');
}

function MediaCenterVote(id, score)
{
	$.get('http://www.head.com/mediacenter/vote.php', { id: id, score: score});
}

function MediaCenterView(id)
{
	$.get('http://www.head.com/mediacenter/view.php', { id: id});
}

function MediaCenterImprint()
{
	window.open('http://www.head.com/corporate/imprint.php', 'resizable=yes,status=yes,scrollbars=yes,toolbars=yes');
}

function MediaCenterNotice()
{
	window.open('http://www.head.com/corporate/legal_notice.php', 'resizable=yes,status=yes,scrollbars=yes,toolbars=yes');
}

function showAllByTag(tagName,dispType)
{
	var elements = document.getElementsByTagName(tagName);
	var i = 0;
	if (dispType == "")
	{
		dispType = "visible";
	}
	while (i < elements.length)
	{
		if (elements[i].id != 'mediacenter')
		{
			elements[i].style.marginLeft = "0px";
		}
		i++;
	}
}

function hideAllByTag(tagName)
{
	var elements = document.getElementsByTagName(tagName);
	var i = 0;
	while (i < elements.length)
	{
		if (elements[i].id != 'mediacenter')
		{
			elements[i].style.marginLeft = "-4000px";
		}
		i++;
	}
}

$(document).ready(function()
{
	var tag = window.location.hash.split("/");
	if (!media_center_is_open && tag[1] == 'mediacenter')
	{
		try {
			pageTracker._setDetectTitle(false);
		} catch(err) {}
		MediaCenterOpen(tag[5], tag[3]);
	}
});