var athl = []; 	/// global obj
var athl_img = [];
	athl.searchNoClose = false;

	athl.headerHeight = 79;
	athl.mainHeight = 378;
	athl.teaserHeight = 150;

	athl.realHeight;
	athl.documentHeight;
	athl.adjustHeight;
	athl.bodyHeight = athl.headerHeight + athl.mainHeight  + athl.teaserHeight;
	athl.msie = $.browser.msie;      // Internet Explorer Win / Mac

$(document).ready(function(){

	$('#turntable').show().hide();

	$('#search input#s').val(searchValueText);

	$('#search input').click( function(){
		if (this.value == searchValueText ) this.value = '';
		$('#searchPlace').show(200);
		athl.searchNoClose = true;
	});
	$('#search input').blur( function(){
		if (this.value == '') this.value = searchValueText;
	});

	$('#searchPlace .close').click( function(){
		$('#searchPlace').hide(200);
	});

	$('#my_athleticum a:not(.active) img').mouseover( function () {
		$(this).attr("src",$(this).attr("src").replace(/.gif/,'_on.gif'));
	}).mouseout	( function () {
		$(this).attr("src",$(this).attr("src").replace(/_on.gif/,'.gif'));
	});

	$('#nav_language a:not(.active) img').mouseover( function () {
		$(this).attr("src",$(this).attr("src").replace(/.gif/,'_on.gif'));
	});
	$('#nav_language a:not(.active) img').mouseout( function () {
		$(this).attr("src",$(this).attr("src").replace(/_on.gif/,'.gif'));
	});

	$('body').click( function(){
		athl.searchClose();
	});
	$('#searchPlace').click( function(){
		athl.searchNoClose = true;
	});


    $('#turntableSmall').click( function(){
		athl.turntable();
	});

	$('.athl-jq-print').click( function(){
		window.print();
	});

	$('#place_shop').click( function(){
		$('#search_box form').attr("action",$('#searchShop').attr('value'));
		$('input#s').attr('name','search');
	});

	$('#place_typo3').click( function(){
		$('#search_box form').attr("action",$('#searchTypo').attr('value'));
		$('input#s').attr('name','tx_indexedsearch[sword]');
	});

	/*$('#link_cvc').click( function() {
		$('#img_cvc').fadeIn("slow");
	});*/
	/*
	$('#promo_1').mouseover( function(){
		$('input#id').attr("value","3028551");
	});
	$('#promo_2').mouseover( function(){
		$('input#id').attr("value","3028568");
	});
	$('#promo_3').mouseover( function(){
		$('input#id').attr("value","3028575");
	});
	*/

	// Basket
	$('a#basket_inactiv').click( function() {
		$("#info_basket").fadeIn("slow");
	});

	// Merkliste
	$('a#basket_inactiv2').click( function() {
		$("#info_basket").fadeIn("slow");
	});


	//if(athl.adjustHeight) athl.heightAjust();


	$('select#cardBrand').ready(function () {
		changeCard();
	});
	$('select#cardBrand').change(function() {
		changeCard();
	});

	function changeCard() {
		var card = "";
		var myDiv;

		//Use code only, if the cardBrand select exists.
		if($('select#cardBrand option:selected').text() != '') {

			//card = document.getElementById('cardBrand');
			card = $('select#cardBrand option:selected').val();

			myDiv = getElementsByClassName('postFinanceText');
			myDiv[0].style.display = 'none';
			myDiv = getElementsByClassName('payPalText');
			myDiv[0].style.display = 'none';
			myDiv = getElementsByClassName('clickAndBuyText');
			myDiv[0].style.display = 'none';
			myDiv = getElementsByClassName('vorauskasseText');
			myDiv[0].style.display = 'none';

			if( card == 'POS' ) { // Post Finance
				changeClass('dark','light');
				var obj=getElementsByClassName('light');
				for(i=0;i<obj.length;i++)
				{
				  obj[i].style.display = 'none';
				}
				myDiv = getElementsByClassName('postFinanceText');
				myDiv[0].style.display = 'block';

			}
			else if( card == 'PAP' ) { // PayPal
				changeClass('dark','light');
				var obj=getElementsByClassName('light');
				for(i=0;i<obj.length;i++)
				{
				  obj[i].style.display = 'none';
				}
				myDiv = getElementsByClassName('payPalText');
				myDiv[0].style.display = 'block';
			}
			else if( card == 'CLB' ) { // Swisscom ClickandBuy
				changeClass('dark','light');
				var obj=getElementsByClassName('light');
				for(i=0;i<obj.length;i++)
				{
				  obj[i].style.display = 'none';
				}
				myDiv = getElementsByClassName('clickAndBuyText');
				myDiv[0].style.display = 'block';
			}
			else if( card == 'VORAUSKASSE' ) { // Bezahlen auf Rechnung / Vorauskasse
				changeClass('dark','light');
				var obj=getElementsByClassName('light');
				for(i=0;i<obj.length;i++)
				{
				  obj[i].style.display = 'none';
				}
				myDiv = getElementsByClassName('vorauskasseText');
				myDiv[0].style.display = 'block';
			}
			else {
				changeClass('light','dark');
				var obj=getElementsByClassName('dark');
				for(i=0;i<obj.length;i++)
				{
				  obj[i].style.display = 'inline';
				}
			}
		}
	}
});



athl.searchClose = function () {
	if( !athl.searchNoClose ) $('#searchPlace').hide(200);
	athl.searchNoClose = false;
}

athl.getLang = function (string){
	return eval('athl.' + athl.lang + '.' + string)
};

athl.heightAjust = function(){
	//alert("athl.realHeight: " + athl.realHeight + " \nathl.bodyHeight:  " + athl.bodyHeight + "\nathl.documentHeight: " + athl.documentHeight + "\nathl.adjustHeight: " + athl.adjustHeight);
	if( athl.realMainHeight < athl.bodyHeight){
		if(athl.msie) {
			$('.sub #main').css('height', athl.realHeight - athl.headerHeight);
			$('.home #main').css('height', athl.adjustHeight);
		}

		$('.sub #main').css('minHeight', athl.realHeight - athl.headerHeight);
		$('.home #main').css('minHeight', athl.adjustHeight);
	}
}

athl.getHeight = function (){
	if (window.innerHeight) athl.realHeight = window.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight) athl.realHeight = document.documentElement.clientHeight;
	else if (document.body) athl.realHeight = document.body.clientHeight;



  if (athl.realHeight > athl.bodyHeight) athl.adjustHeight = athl.mainHeight + (athl.realHeight - athl.bodyHeight)
  else if( athl.adjustHeight ) athl.adjustHeight = athl.mainHeight; // Value has been set bevor and is now minimum value
}

athl.turntable = function( action ){
	if(action == 'show'){
		$('#turntable').show();
	} else if( action == 'hide'){
		$('#turntable').hide();
	} else {
		if($('#turntable').css('display') == 'none') $('#turntable').show();
		else $('#turntable').hide();
	}
}

$(window).resize(function(){
	athl.getHeight();
	athl.heightAjust();
});

athl.getHeight(); // Get height of Window

function makeVisible () {
	if (document.getElementById("cart_login").style.display == 'none') {
		$("#cart_login").show("fast");
		return;
	}

  	if (document.getElementById("cart_login").style.display == 'block') {
  		$("#cart_login").hide("fast");
  		return;
  	}
}

function getElementsByClassName(class_name)
      {
        var all_obj,ret_obj=new Array(),j=0,teststr;

        if(document.all)all_obj=document.all;
        else if(document.getElementsByTagName && !document.all)
          all_obj=document.getElementsByTagName("*");

        for(i=0;i<all_obj.length;i++)
        {
          if(all_obj[i].className.indexOf(class_name)!=-1)
          {
            teststr=","+all_obj[i].className.split(" ").join(",")+",";
            if(teststr.indexOf(","+class_name+",")!=-1)
            {
              ret_obj[j]=all_obj[i];
              j++;
            }
          }
        }
        return ret_obj;
      }

function changeClass(alt,neu)
{
  var obj=getElementsByClassName(alt);

  for(i=0;i<obj.length;i++)
  {
    obj[i].className=neu;
  }
}

function makeLight() {
	document.getElementsByClassName("_light").className = 'light';
}

function makeDark() {
	document.getElementsByClassName("light").className = '_light';
}

function changeBrand() {

}
