$(document).ready( function() {
	var $winMinHeight = '750';
	var $para_ShowOthers = getHTTPGetVars('showothers');
	//$('.retailerSearch input:text').parent().css('display','none');
	//$('a.showothers').attr('href', 'index.php?id=163&L=0&showothers=1');
	
	onResizeWindow();
		$(window).resize( function() {
			onResizeWindow();
			onResizeWindow();
			var $winHeight = '';
			if( parseInt($(window).height()) < $winMinHeight ) {
		        $winHeight = $winMinHeight;
		   } else {
		        $winHeight = $(window).height();
		   }
			$('#flashContent')
				.attr('width', $(window).width())
				.attr('height', $winHeight)
				.css('display', 'block');
		});
		onResizeWindow();
	
	// ----------------------------------------------------------------------------------------------
   // retailer search
   // ----------------------------------------------------------------------------------------------
	if( $('*').is(".retailerSearch") ) {
		$.preloadImages("fileadmin/user_upload/concord/europa_D.gif", 
						"fileadmin/user_upload/concord/europa_AUS.gif", 
						"fileadmin/user_upload/concord/europa_CH.gif",
						"fileadmin/user_upload/concord/europa_F.gif", 
						"fileadmin/user_upload/concord/europa_ESP.gif", 
						"fileadmin/user_upload/concord/europa_GB.gif",
						"fileadmin/user_upload/concord/europa_IT.gif");
		$.changeImage( $('form.retailerSearch input:radio:checked').attr('value') );
		$('form.retailerSearch input:radio').change( function() {
			$.changeImage( $('input:checked').attr('value') );
		});
		
		$('div.search-results').jScrollPane({'scrollbarMargin':'0', 'showArrows':'true'});
		$('a.showothers').click( function(e) {
			e.preventDefault();
			$('input:text').val('');
			$('input:checked').attr('checked', false);
			$('#showothers').attr('value', '1');
			$('form.retailerSearch').attr('action', 'index.php?id=163&L=0&showothers=1');
         $('form.retailerSearch').submit();
		});
		$('div.el-3 div.jScrollPaneContainer').css('width', '300px');
		$('div.el-3 div.jScrollPaneContainer div.search-results').css('width', '300px');
		$('div.search-results table.contenttable td:even').css('width', '60px');
		$('div.search-results table.contenttable td:even p').css({'width':'60px'});
		$('div.search-results table.contenttable td:odd').css('width', '200px');
		$('div.search-results table.contenttable td:odd p').css({'width':'200px'});
	}
	
	// ----------------------------------------------------------------------------------------------
   // news
   // ----------------------------------------------------------------------------------------------
	if( $('*').is("div.scrollable") ) {
		//console.log( $("div.scrollable") );
      $("div.scrollable").scrollable({size:3,horizontal:true,itemClick:false});
	}
	if( $('*').is('div.jScrollPaneContainer') && ! $('*').is('div#acc') ) {
		
      if( $('*').is('div#content') ) { 
         off = $('div#content div:last').offset();
         if( (off.top+$('div#content div:last').height()) < $('#main-wrap').height() ) {
            $('div#content').css('min-height', '270px');
         }
      }
      
      $('div.text').slideDown('fast', function() {
			$('div.text').jScrollPane({'scrollbarOnLeft':'true', 'showArrows':'true'});
         if( $('div.text').length > 0 ) {
            if( $('.jScrollArrowDown').length ) {
               $('div.text')[0].scrollTo(0);
            }
         }
         
			$('.news-single-img').css('padding-top', '0')
								 //.css('top', parseInt($('.image').css('height'))/2-parseInt($('.news-single-img img').css('height'))/2)
								 .css('display', 'block');
			$('div .news-single-img img:eq(1)').fadeIn();
		});
	}
	if( $('*').is('div.news-single-img') ) {
		//$('div.news-single-img img').css('top', parseInt($('div.image').css('height'))/2-parseInt($('div.news-single-img').css('height'))/2+'px');
	}
	if( $('*').is('div.items') ) {
		$('div.items a').each( function() {
			//$(this).attr('href', 'javascript:tb_show("", "'+$(this).attr('href')+'&type=601&height=425&width=520")');
			//$(this).attr('href', 'javascript:tb_show("", "'+$(this).attr('href')+'&type=601&height=408&width=520&KeepThis=true&TB_iframe=true")');
			$(this).attr('href', 'javascript:tb_show("", "'+$(this).attr('href')+'&type=601&height=468&width=670&KeepThis=true&TB_iframe=true", "news")');
			$(this).attr('rel', 'news');
			//$(this).attr('class', 'thickbox').attr('href', 'http://www.concord.de/c6d3e1eba587564cf34aedad965a9016/fileadmin/tpl_html/thickbox_news.html?height=428&width=550&KeepThis=true&TB_iframe=true');
			//$(this).attr('href', 'javascript:tb_show("", "http://www.rptc.de&height=428&width=550&KeepThis=true&TB_iframe=true")');
		});
		// $('#TB_ajaxContent').bind('load', function() {
			// alert(1123);
			// $('div.text').jScrollPane({'scrollbarOnLeft':'true', 'showArrows':'true'});
		// });
	}
	
   // ----------------------------------------------------------------------------------------------
   // sub sub navi
   // ----------------------------------------------------------------------------------------------
   if( $('#subSubNavi > ul > li').length > 0 ) {
      $('#subSubNavi').css('background-color', $('#subSubNavi > ul').css('background-color'));
    }
   
   // ----------------------------------------------------------------------------------------------
   // main / sub player
   // ----------------------------------------------------------------------------------------------
   if( $('*').is('#mainPlayer') ) {
         
         // show sub player for active main player button
         $('#mainPlayer ul li a[class=active]').siblings().css('display', 'block');
         if( $('#mainPlayer ul li > a').hasClass('active') ) {
            $('#subPlayer').css('background', '#515254');
         }
         
         // show/hide sub player on hover if no main player button is active
         if( ! $('#mainPlayer > ul > li > a').hasClass('active') ) {
            $('#mainPlayer > ul > li').hover( function() {
               if( $(this).find('ul li').length > 0 ) {
                  $('#mainPlayer ul li > a').removeClass('active');
                  $(this).find('a:first').addClass('active');
                  $(this).find('ul').css('display', 'block');
                  $('#subPlayer').css('background', '#515254');
               }
            }, function() {
               if( $(this).find('ul li').length > 0 ) {
                  $('#mainPlayer ul li > a').removeClass('active');
                  $(this).find('ul').css('display', 'none');
                  $('#subPlayer').css('background', '#000');
               }
            });
         }
         
      }
   
   
	$('body').append('<div id="preloader"></div>');
	$('div#preloader').css({'display':'none', 'top':'-1000px', 'left':'-1000px'})
	
	var hasSubPlayer = $('*').is('#subPlayer a');
	if( hasSubPlayer ) {
		//$('#subPlayer a').each( function() {
			// $('div.csc-textpic-imagewrap').css({'width':'100%'});
			// 			$('dl.csc-textpic-image').css({'display':'none'});
			// 			$('div.csc-textpic-imagewrap dl:first-child').css({'width':'100%', 'position':'relative', 'left':'0', 'margin':'0 auto 0 auto'}).fadeIn('5000');
			// 			$('div.csc-textpic-imagewrap dl:first-child dt').css({'width':'100%', 'position':'relative', 'left':'0', 'margin':'0 auto 0 auto'});
		//});
	}
	
	$('#subPlayer a').click( function(e) {
      $('#subPlayer a').removeClass('active');
      $(this).attr('class', 'active');
   });
	  
	
	if ($para_ShowOthers==0){
		//$('.el-3').css('display','none');
	}else{
		$('.el-3').css('display','block');
      $('.retailerSearch input:text').parent().css('display','none');
      $('.retailerSearch .searchfield:last').css('display','none');
      $('a.showothers').css('font-weight', 'bold');
	}
	
	$('.retailerSearch input:radio').click( function(e) {
		$('.el-3').css('display','none');
		$('.retailerSearch input:text').parent().css('display','block');
      $('.retailerSearch .searchfield:last').css('display','block');
      $('a.showothers').css('font-weight', 'normal');
	});
	
	$('.navi a[title=HÄNDLERSUCHE]').click( function() {
		$('.retailerSearch input:text').parent().css('display','block');
		 $('#zip').focus();
		return false;
	});
});

function onResizeWindow() {
	var $w = $(window);
   var $winWidth = $w.width();
	var $winHeight = $w.height();
	var $logoTop = "22px";
	if( $winHeight >= 650 ) {
		var $plusHeight = Math.floor(($winHeight-650));
		$('#header').css('height', parseInt($('#header').css('min-height'))+$plusHeight*0.1+'px');
		$('#mainNavi').css('height', parseInt($('#mainNavi').css('min-height'))+$plusHeight*0.1+'px');
		$('#logo').css('top', ((parseInt($('#header').css('height')))/2)-($('#logo img').attr('height')/2)+'px');
		if( ! $('*').is('#contentFlash') ) {
			$('#main').css('height', parseInt($('#main').css('min-height'))+$plusHeight*0.5
										    -(parseInt($('#subNavi').css('height')))
											 -(parseInt($('#subNavi').css('height')))+'px');
			$('#content').css('top', (parseInt($('#main').css('height'))/2)-(parseInt($('#content').css('height'))/2)+'px');
			//$('#player').css('height', parseInt($('#player').css('min-height'))+($plusHeight*0.34)+'px');
			$('#player').css('height', parseInt($('#player').css('min-height'))+($plusHeight*0.49)+'px');
			$('#footer').css('height', parseInt($('#footer').css('min-height'))+$plusHeight*0.06+'px');
		} else {
			$('#main').css({'height':'690px', 'padding-bottom':'0'});
		}
	} else {
		$('#header').css('height', $('#header').css('min-height'));
		$('#logo').css('top', $logoTop);
		$('#mainNavi').css('height', $('#mainNavi').css('min-height'));
		if( ! $('*').is('#contentFlash') ) {
			$('#main').css('height', $('#main').css('min-height'));
			//$('#content').css('height', $('#content').css('min-height'));
			$('#content').css('height', '370px');
			$('#player').css('height', $('#player').css('min-height'));
			$('#footer').css('height', $('#footer').css('min-height'));
		} else {
			$('#main').css({'height':'690px', 'padding-bottom':'0'});
		}
	}
   //center main / sub player
   if( $('#mainPlayer > ul > li').length > 0 ) {
         var $mpWidth = parseInt($('#mainPlayer > ul > li').css('width'))
                         * ($('#mainPlayer > ul > li').length - 1)
                         + parseInt($('#mainPlayer > ul > li:last').css('width'));
         var $mpLeft = ($winWidth/2) - ($mpWidth/2);
         $('#mainPlayer > ul').css('width', $mpWidth);
         $('#mainPlayer > ul').css('left', $mpLeft+'px');
         //$('#mainPlayer > ul > li > ul').css('left', '0');
         //$('#mainPlayer > ul > li > ul').css('width', $winWidth+'px');
   }
   
   // company / accordion
   // if( $('#content').height() > $('#main-wrap').height() ) {
      // if( $('*').is('div#acc') ) { 
         // $('.jScrollArrowUp').remove();
         // $('.jScrollArrowDown').remove();
         // $('div.text').jScrollPane({'scrollbarOnLeft':'true', 'showArrows':'true'});
      // }
   // }
}

function startJQuery() {
	$('div.text').jScrollPane({'scrollbarOnLeft':'true', 'showArrows':'true'});
	$('div.news-single-img img').css('top', parseInt($('div.image').css('height'))/2-parseInt($('div.news-single-img').css('height'))/2+'px');
	
}

jQuery.preloadImages = function() {
  for(var i = 0; i<arguments.length; i++) {
     jQuery("<img>").attr("src", arguments[i]);
  }
}
jQuery.changeImage = function() {
	switch( arguments[0] ) {
		case "54":
			$('div.el-2 > img').attr('src', 'fileadmin/user_upload/concord/europa_D.gif');
			break;
		case "13":
			$('div.el-2 > img').attr('src', 'fileadmin/user_upload/concord/europa_AUS.gif');
			break;
		case "41":
			$('div.el-2 > img').attr('src', 'fileadmin/user_upload/concord/europa_CH.gif');
			break;
		case "72":
			$('div.el-2 > img').attr('src', 'fileadmin/user_upload/concord/europa_F.gif');
			break;
		case "65":
			$('div.el-2 > img').attr('src', 'fileadmin/user_upload/concord/europa_ESP.gif');
			break;
		case "74":
			$('div.el-2 > img').attr('src', 'fileadmin/user_upload/concord/europa_GB.gif');
			break;
		case "104":
			$('div.el-2 > img').attr('src', 'fileadmin/user_upload/concord/europa_IT.gif');
			break;
		default:
			$('div.el-2 > img').attr('src', 'fileadmin/user_upload/concord/europa_blank.gif');
			break;
	}
}

HTTP_GET_VARS=new Array();
function getHTTPGetVars(para_name){
	strGET=document.location.search.substr(1,document.location.search.length);
	if(strGET!='')
		{
		gArr=strGET.split('&');
		for(i=0;i<gArr.length;++i)
			{
			v='';vArr=gArr[i].split('=');
			if(vArr.length>1){v=vArr[1];}
			HTTP_GET_VARS[unescape(vArr[0])]=unescape(v);
			}
		}
		
	return GET(para_name)==1 ? GET(para_name) : 0 ;
}

function GET(v)
{
	if(!HTTP_GET_VARS[v]){return 'undefined';}
	return HTTP_GET_VARS[v];
}
