$(document).ready(function(){
	
	
	$('#infobox_wrapper .tabcontent').hide();
	$('#infobox_wrapper .tabcontent:first').show();
	$('#infobox li:first a').addClass("active");
	$('#infobox li a').click(function(){
		$('#infobox li a').removeClass("active");
		$(this).addClass("active");
		tab_id = $(this).attr("rel");
		
		$('#infobox_wrapper .tabcontent').hide();
		$(tab_id).show();
		return false;
	});
	
	
	$('#showbox_wrapper .tabcontent').hide();
	$('#showbox_wrapper .tabcontent:first').show();
	$('#showbox li:first a').addClass("active");
	$('#showbox li a').click(function(){
		$('#showbox li a').removeClass("active");
		$(this).addClass("active");
		tab_id = $(this).attr("rel");
		$('#showbox_wrapper .tabcontent').hide();
		$(tab_id).show();
		return false;
	});
	
	$('#linkbox_wrapper .tabcontent').hide();
	$('#linkbox_wrapper .tabcontent:first').show();
	$('#linkbox li:first a').addClass("active");
	$('#linkbox li a').click(function(){
		$('#linkbox li a').removeClass("active");
		$(this).addClass("active");
		tab_id = $(this).attr("rel");
		$('#linkbox_wrapper .tabcontent').hide();
		$(tab_id).show();
		return false;
	});
	
	
	$('#retailersbox_wrapper .tabcontent').hide();
	$('#retailersbox_wrapper .tabcontent:first').show();
	$('#retailersbox li:first a').addClass("active");
	$('#retailersbox li a').click(function(){
		$('#retailersbox li a').removeClass("active");
		$(this).addClass("active");
		tab_id = $(this).attr("rel");
		$('#retailersbox_wrapper .tabcontent').hide();
		$(tab_id).show();
		return false;
	});
	
	
	/* Presentational */
	$('#infobox td:even').addClass("label");
	$('#showbox td:even').addClass("label");
	$('.doubletable table:odd').addClass("right");
	$('.tripletable').find("tr:first").addClass("label");

	
	$('.convert').each(function(){
		apt_size = $(this).attr("class");
		if(apt_size.match("m") == "m") {
			$('.convert.m .channelteaser').each(function(){
				msrc = $(this).find('img').attr('src');
				msrc = msrc.replace(/470a/, "224a");
				$(this).find('img').attr('src',msrc);
				$(this).addClass("med");
			});
		}
		if(apt_size.match("s") == "s") {
			$('.convert.s .channelteaser').each(function(){
				$(this).addClass("super");
			});
		}
		if(apt_size.match("xl") == "xl") {
			$('.convert.xl .channelteaser').each(function(){
				ssrc = $(this).find('img').attr('src');
				ssrc = ssrc.replace(/470a/, "348a");
				$(this).find('img').attr('src',ssrc);
			});
		}
	});
	chp = $('#ch_pagenavi').html()
	$('#ch_pagenavi').parent().append('<div id="ch_pagenavi_bottom">'+chp+'</div>');
	
	
	$(".dropdown img.flag").addClass("flagvisibility");

	$(".dropdown dt").click(function() {
	    $(".dropdown dd ul").toggle();
	});
    
	$(".dropdown dd ul li a").click(function() {
	    var text = $(this).html();
	    $(".dropdown dt a span").html(text);
	    $(".dropdown dd ul").hide();
	    // $("#result").html("Selected value is: " + getSelectedValue("sample"));
	});
    
	function getSelectedValue(id) {
	    return $("#" + id).find("dt a span.value").html();
	}
    
	$(document).bind('click', function(e) {
	    var $clicked = $(e.target);
	    if (! $clicked.parents().hasClass("dropdown"))
	        $(".dropdown dd ul").hide();
	});
    
    
	$("#flagSwitcher").click(function() {
	    $(".dropdown img.flag").toggleClass("flagvisibility");
	});
	
	$("a[href$=pdf]").each(
	   function(){
	      $(this).attr('target', '_blank');
	});
	$("a[href^=http]").each(
	   function(){
		  if(this.href.indexOf(location.hostname) == -1 && this.href.indexOf("supersportler") == -1) { 
	      $(this).attr('target', '_blank');
	    }
	});
	

	
	
	$('#start_slider') 
	.cycle({ 
	    fx:     'fade', 
	    speed:  1000, 
	    timeout: 6000
	});
	
});
