/*
 * (c) 2010, Philipp Anger
 *  
 */


function isActiveButton(href){	
	var regexS = "[\\?&]mod=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec(href);
	
	if(mod > 8 && mod < 13 && results[1] == 2){
		return true;
	} else if(results[1] == mod){
		return true;
	}else {
		return false;
	}
}


function createNaviButtons(){
	var width,pos,id;
	var naviPosDE = {'news':'0px','sortiment':'96px','shop':'240px','machines':'310px','service':'489px','contactperson':'573px','brands':'721px','aboutus':'805px'};
	var naviPosEN = {'news':'0px','sortiment':'86px','shop':'194px','machines':'278px','service':'430px','contactperson':'528px','brands':'690px','aboutus':'786px'};
	var naviWidthDE = {'news':'96px','sortiment':'144px','shop':'70px','machines':'179px','service':'84px','contactperson':'148px','brands':'84px','aboutus':'95px'};
	var naviWidthEN = {'news':'86px','sortiment':'108px','shop':'84px','machines':'152px','service':'98px','contactperson':'162px','brands':'96px','aboutus':'114px'};
	
	$('#head-navi a').each(function(){
		id = $(this).attr('id');
	
		if(lang == 'EN'){
			width = naviWidthEN[id];
			pos = naviPosEN[id];
		} else {
			width = naviWidthDE[id];
			pos = naviPosDE[id];		
		}
		
		$('#'+id).addClass('navi-item'+lang).append($('<span></span>').addClass('hide').text($('#'+id+'_value').val()));
		
		if(isActiveButton($('#'+id).attr('href'))){
			$('#'+id).css({'float':'left','height':'40px','width':width,'background': 'url(source/images/navi_active'+lang+'.jpg) -'+pos+' 0 no-repeat'});
		} else {
			$('#'+id).css({'float':'left','height':'40px','width':width,'background': 'url(source/images/navi_inactive'+lang+'.jpg) -'+pos+' 0 no-repeat'});
		}		
	});
}


function createSortimentButtons(){
	var width,pos,id;
	var naviPosDE = {'sort_gt':'0px','sort_ah':'130px','sort_eq':'268px','sort_at':'374px'};
	var naviPosEN = {'sort_gt':'0px','sort_ah':'107px','sort_eq':'244px','sort_at':'334px'};
	var naviWidthDE = {'sort_gt':'130px','sort_ah':'138px','sort_eq':'106px','sort_at':'126px'};
	var naviWidthEN = {'sort_gt':'107px','sort_ah':'137px','sort_eq':'90px','sort_at':'166px'};
	
	$('#sortiment-navi a').each(function(){
		id = $(this).attr('id');
	
		if(lang == 'EN'){
			width = naviWidthEN[id];
			pos = naviPosEN[id];
		} else {
			width = naviWidthDE[id];
			pos = naviPosDE[id];		
		}
		
		$('#'+id).addClass('sort-item'+lang).append($('<span></span>').addClass('hide').text($('#'+id+'_value').val()));
		
		if(isActiveButton($('#'+id).attr('href'))){
			$('#'+id).css({'float':'left','height':'30px','width':width,'background': 'url(source/images/sort_active'+lang+'.jpg) -'+pos+' 0 no-repeat'});
		} else {
			$('#'+id).css({'float':'left','height':'30px','width':width,'background': 'url(source/images/sort_inactive'+lang+'.jpg) -'+pos+' 0 no-repeat'});
		}		
	});
}


function createSortimentIcons(){
	agriculturaltechnologyTitle = $('#agriculturaltechnology_value').val();
	equitationTitle = $('#equitation_value').val();
	animalhusbandryTitle = $('#animalhusbandry_value').val();
	gardentoolsTitle = $('#gardentools_value').val();
	
	$('#agriculturaltechnology').addClass('head-sortimentimage').css({'background-image':'url(source/images/icons/traktor_inactive.jpg)'}).append($('<span></span>').text('Landtechnik inaktiv'));
	$('#equitation').addClass('head-sortimentimage').css({'background-image':'url(source/images/icons/horseshoe_inactive.jpg)'}).append($('<span></span>').text('Reitsport inaktiv'));
	$('#animalhusbandry').addClass('head-sortimentimage').css({'background-image':'url(source/images/icons/cow_inactive.jpg)'}).append($('<span></span>').text('Tierzucht inaktiv'));
	$('#gardentools').addClass('head-sortimentimage').css({'background-image':'url(source/images/icons/secateurs_inactive.jpg)'}).append($('<span></span>').text('Gartentechnik inaktiv'));
}


function initNaviSlider(){
	createNaviButtons();	
	createSortimentIcons();
	
	$('.removehidden').remove();
}




