var Page = {
	initialize: function() {
	


// input focus color
   ffocus = $$('input[type=text], input[type=password], textarea');
   ffocus.each(function(focus){
   		focus.addEvent('focus', function(){focus.setStyles({backgroundColor:'#fefa8f', color:'#000000'});});
    	focus.addEvent('blur', function(){focus.setStyles({backgroundColor:'#fefefe',color:'#585757'});});
  	});

// input jump-next to text input-field
   ifocus = $$('input[type=text], input[type=password], textarea');
   ifocus.each(function(myInput){
   		myInput.addEvent('keyup', function (){
			myLen = this.getProperty('maxlength');
			if (myLen==-1){return;}
			
			// Die Moo-Tools-Lib ist hier nicht mehr verfuegbar ?!
			// deshalb schreibe ich dies hier in stdandard-JS
			// es ist sperrig und haesslich - klappt aber.

			if(this.value.length >= myLen) {
				//alle <input>-Felder
				var theForm = this.form ;
				var myForm = theForm.getElementsByTagName('input');
				
				var theLast = myForm[myForm.length-1];
				var myPos = null;
				for ( var p=0; p<myForm.length; p++ ) {
					if( myForm[p] == this )	{myPos = p+1; break;};
				}
				if ( theLast == this)  //getElements('input')[0]
					// sind wir bereits im letzten feld ?
					{console.log("no jump,return");
					return;}
				else // filter alle input-Elemente vom typ =='text' oder 'passwd'
				{ 
					var allowedTypes =  [ 'password', 'text' ];
					var myNext = false;
					for ( var p=myPos; p<myForm.length; p++ ) {
							var myField = myForm[p] ;
				    		if ( allowedTypes.contains( myField.type ) && !myField.readonly )
								{ myNext = myForm[p]; break;}
					} //-for
					//console.log( myNext );
					if ( myNext ) { myNext.focus(); }
					return;
				}
			}
		}//fn-close
		 );//each-close?
  	});

/**
// input jump-next to text input-field
   ifocus = $$('input[type=text], input[type=password], textarea');
   ifocus.each(function(myInput){
   		myInput.addEvent('keyup', function (){
			myLen = this.getProperty('maxlength');
			//console.log("here myLen: %s",myLen);
			if (myLen==-1){return;}
			
			if(this.value.length >= myLen) {
//				myForm = this.form.getElements('input[type=text]');
				myForm = $$('#content input[type=text], input[type=password]');
				myPos = myForm.indexOf(this);

				if (myPos+1 < myForm.length ){ 
					myNext = myForm[myPos+1];
					console.log('\t "%s" jumps to "%s"=>', this.id, myNext.id );
					myForm[myPos+1].focus(); }
			}
		}//fn-close
		 );//each-close?
  	});
**/
  	
// focus color on form advice box
   ffocus2 = $$('input');
   
   ffocus2.each(function(focus2){
   var etag = focus2.getProperty('alt');
   var etag2 = $('box_'+etag);
   		focus2.addEvent('focus', function(){
   			if (etag2) {
   				etag2.removeClass('bgwhite').addClass('bgbeige');
     		} 			
   		});
   		
   		focus2.addEvent('blur', function(){
   			if (etag2) {
   				etag2.removeClass('bgbeige').addClass('bgwhite');
     		} 			
   		});
  	});
  	
  	
// change radio button on focus input fields (in checkls und login)
   radioCh = $$('input');
   radioCh.each(function(rchange){
   var rtag = rchange.getProperty('alt');
   		rchange.addEvent('focus', function(){
   			if ($('select_'+rtag)) {
   				$('select_'+rtag).setProperty('checked', 'checked');
     		} 			
   		});
  	});
  	
// change radio button on focus input fields (in checkls und login)
   radioCh2 = $$('#content .fb_select');
   radioCh2.each(function(rchange2){
   var rtag2 = rchange2.getProperty('title');
   		rchange2.addEvent('click', function(){
   			if ($('select_'+rtag2)) {
   				$('select_'+rtag2).setProperty('checked', 'checked');
     		} 			
   		});
  	});
  	


// buttons over
    button = $$('.btn');
    button.each(function(btn){
    	btn.addEvent('mouseover', function(){btn.setStyles({backgroundPosition:'bottom center'});});
    	btn.addEvent('mouseout', function(){btn.setStyles({backgroundPosition:'top center'});});
   	});

// input text replace SUCHE
if ($('field_suche')) {
stext = $('field_suche');
	stext.addEvent('focus', function() {
    	if(stext.value == "Suche" && geklickt != "yes") {
			stext.value = '';
			var geklickt = "yes";
		}});
    stext.addEvent('blur', function() {		
    	if (stext.value == "") {
			stext.value = 'Suche';
		}});
}			
		
// input text replace GRAVUR
if ($('gravur')) {
ftext = $('gravur');
	ftext.addEvent('focus', function() {
    	if(ftext.value == "Ohne Gravur" && geklickt2 != "yes") {
			ftext.value = '';
			var geklickt2 = "yes";
		}});
    ftext.addEvent('blur', function() {		
    	if (ftext.value == "") {
			ftext.value = 'Ohne Gravur';
		}});
}		
		
// fx box stretch width and height
    fxbox = $$('#content .box');
    fxbox.each(function(box){
		boxWidth = (box.getSize().size.x)-12;   		
    	boxHeight = (box.getSize().size.y)-10;
    	box.getElements('.wfx2').setStyles({width: boxWidth+2,visibility:'visible'});
    	box.getElements('.wfx').setStyles({width: boxWidth,visibility:'visible'});
    	box.getElements('.hfx').setStyles({height: boxHeight,visibility:'visible'});
   	});
   	
   	
// fx box2 stretch height (in Check_ok)
    fxbox2 = $$('#content .box2');
    fxbox2.each(function(box2){

    var badvice1 = box2.getProperty('id');
    badvice2 = $('box_'+badvice1);
        if ($(badvice2)) {
        	boxHeight = (box2.getSize().size.y)-20;
    		badvice2.getElements('.hfx').setStyles({height: boxHeight,visibility:'visible'});
    	}
   	});
   	
// fx res_middle nav position center (in result)
    if ($('res_middle')) {
    	resWidth = $('res_container').getSize().size.x;
        resLeft = (resWidth/2)-(($('res_middle').getSize().size.x)/2);
    	$('res_middle').setStyles({left: resLeft,visibility:'visible'});
    }

// fx kat_center position center (in okat.html)
	fxkatcenter = $$('#content .kat_center');
    fxkatcenter.each(function(box3){
    if ($$('#content .kat_center')) {
        katWidth = box3.getParent().getSize().size.x;
        katLeft = (katWidth/2)-((box3.getSize().size.x)/2);
    	box3.setStyles({left: katLeft,visibility:'visible'});
    }
});

// hover for crappy ie
if (window.ie6) {
	if ($('navstart')) {
		navli = $('navstart').getChildren().filterByTag('li');
    	navli.each(function(lis){
    		lis.addEvent('mouseover', function(){lis.addClass('over');});
    		lis.addEvent('mouseout', function(){lis.removeClass('over');});
   		});			
 	}
 } 

// opens external (class="ext" rel="small" or rel="big") links in a new window
$$('a.ext').each(function(popup){
var link = popup.getProperty('href');

	if (popup.getProperty('rel') == 'small'){
		popWidth = '650';
		popHeight = '450';
	} else if (popup.getProperty('rel') == 'big'){
		popWidth = '820';
		popHeight = '450';	
	} else if (popup.getProperty('rel') == 'pict'){
		popWidth = '690';
		popHeight = '700';	
	}
	else if (popup.getProperty('rel') == 'okat'){
		popWidth = '820';
		popHeight = '700';	
	}
	else if (popup.getProperty('rel') == 'lupe'){
		popWidth = '820';
		popHeight = '700';	
	}
	else if (!popup.getProperty('rel')){
		var popWidth = "650";
		var popHeight = "450";
	} 
	
	popup.onclick = function() {
		window.open(link,'pop','status,scrollbars,resizable,width='+popWidth+',height='+popHeight+'');
		return false;
	};
});

// aktuelle Renner + aktuelle Themen picture link
pictlink = $$('.pictlink');
pictlink.each(function(plink){
   	plink.addEvent('click', function(){
   		linkObj = plink.getParent().getParent();
   		pl = linkObj.getProperty('href');
   		window.location.href = pl;
   	});
});


// Seitenleiste BoxLinks Rubrik Ihr Warenkorb im Bodyheader
rublink = $$('.rublink');
rublink.each(function(rlink){
   	rlink.addEvent('click', function(){
   		rlinkObj = rlink.getElement('a');
   		rpl = rlinkObj.getProperty('href');
   		window.location.href = rpl;
   	});
});

  	
 
// set body target
window.name='klnlmain';
window.focus();


	//if ($('lsmaga')) {
		navlsmaga = $$('lsmaga').filterByTag('a');
    	navlsmaga.each(function(lsm){
    		lsm.addEvent('mouseover', function(){lsm.addClass('over');});
    		lsm.addEvent('mouseout', function(){lsm.removeClass('over');});
   		});			
 	//}
 	
 	
 	
 
}
};

window.addEvent('domready', function(){ Page.initialize();});

