try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}


function getElementsByClass(searchClass,node,tag) {

	var classElements = new Array();

	if ( node == null )

		node = document;

	if ( tag == null )

		tag = '*';

	var els = node.getElementsByTagName(tag);

	var elsLen = els.length;

	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");

	for (i = 0, j = 0; i < elsLen; i++) {

		if ( pattern.test(els[i].className) ) {

			classElements[j] = els[i];

			j++;

		}

	}

	return classElements;

 }
 
 
 
 /*
 
 function showResultsProducts () {
	alert('asdas');
	var produkt_list_items = document.getElementById('produkt_list_items');
	 var search_content = document.getElementById('search_content');
	 var search_news = document.getElementById('search_news');
	 if(produkt_list_items) {produkt_list_items.style.display = 'block'}
	 if(search_content) {search_content.style.display = 'none'}
	 if(search_news) {search_news.style.display = 'none'}
	 return false;
 }
 
 function showResultsContent () {
	 var produkt_list_items = document.getElementById('produkt_list_items');
	 var search_content = document.getElementById('search_content');
	 var search_news = document.getElementById('search_news');
	 if(produkt_list_items) {produkt_list_items.style.display = 'none'}
	 if(search_content) {search_content.style.display = 'block'}
	 if(search_news) {search_news.style.display = 'none'}
	 return false; 
 }
 
 
 function showResultsNews () {
	var produkt_list_items = document.getElementById('produkt_list_items');
	var search_content = document.getElementById('search_content');
	var search_news = document.getElementById('search_news');
	if(produkt_list_items) {produkt_list_items.style.display = 'none'}
	if(search_content) {search_content.style.display = 'none'}
	if(search_news) {search_news.style.display = 'block'}
	 return false;  
}

*/
 
 
 


$.fn.clearForm = function() {
	return this.each(function() {
   	var type = this.type, tag = this.tagName.toLowerCase();   
          if (tag == 'form')   
            return $(':input',this).clearForm();  
          if (type == 'text' || type == 'password' || tag == 'textarea')   
            this.value = '';  
          else if (type == 'checkbox' || type == 'radio')   
            this.checked = false;  
          else if (tag == 'select')  
            this.selectedIndex = -1;  
        });
      };



 $(document).ready(function() {
		
		$('body').removeClass('static');
		
		$('.text input').bind('focus', function(){
	        if( this.value == this.defaultValue ) {
	            this.value = "";
	        }
	    });
	    $('.text input').bind('blur', function(){
	        if( !this.value.length ) {
	            this.value = this.defaultValue;
	        }
	    });
	    $('#filter_form input').bind('click', function(){
	        this.form.submit();
	    });
	    $('#clear-form').bind('click', function(){
	        $('form').clearForm();
	        return false;
	    });
	    
	    
	    
	function produktMenu () {
	
		var produkt_menu_wrapper_toggler = document.getElementById('produkt_menu_wrapper_toggler');
		
		if(produkt_menu_wrapper_toggler) {
		
				$('#produkt_menu_wrapper_toggler').hover(function () {
					$('#produkt_menu_wrapper').css('display','block');
					return false;
				});
				
				
				
		}
	
	}
	
	
	function produktFeatures () {
		
	
		var produkt_features = document.getElementById('produkt_features');
		if(produkt_features) {
			
		var produkt_features_li_arr = 	produkt_features.getElementsByTagName('li');
		
		var produkt_features_li = [];
		
		for(x=0; x<produkt_features_li_arr.length; x++) {
			if(produkt_features_li_arr[x].className=='feature_li') {
				produkt_features_li.push(produkt_features_li_arr[x]);
			}
		}
		
			
		 $('#produkt_features .feature').hide();
	 	 $('#produkt_features .feature:first').show();
	 	 $('#produkt_features li .feature_toggler_wrapper a').click(
		
		function() {
		  var checkElement = $(this).parent().next();
		  if((checkElement.is('div')) && (checkElement.is(':visible'))) {
			return false;
			}
		  if((checkElement.is('div')) && (!checkElement.is(':visible'))) {
			$('#produkt_features .feature:visible').slideUp('normal');
			checkElement.slideDown('normal');
			
			for(i=0; i<produkt_features_li.length; i++) {
				produkt_features_li[i].setAttribute('id','');	
			}
			
			$(this).parent().parent().attr('id','open_feature');
			return false;
			}
		  }
		);
		}
	}
	
	function replaceSelectForm () {
		var select_form = document.getElementById('select_form');
		if(!select_form) {return false}
		var select_options =  select_form.getElementsByTagName('option');
		select_form.value =  select_options[0].value;
		
		var dl = document.createElement('dl');
		dl.className = 'user_list_menu';
		dl.setAttribute('id','select_dl');
		
		var dt = document.createElement('dt');
		dt.innerHTML = select_options[0].innerHTML;
		
		var dd = document.createElement('dd');
		var ul = document.createElement('ul');
		
		for(i=1; i<select_options.length; i++) {
			var li =  document.createElement('li');
			if(i==1) {li.className = 'first'}
			var lk = document.createElement('a');
			
			lk.setAttribute('href','#');
			lk.setAttribute('rel',select_options[i].value);
			lk.innerHTML = select_options[i].innerHTML;
			li.appendChild(lk);
			ul.appendChild(li);
		}
		
		dd.appendChild(ul);
		dl.appendChild(dt);
		dl.appendChild(dd);
		
		select_form.parentNode.appendChild(dl);
		
		
		var select_dl =  document.getElementById('select_dl');
		var select_dt = select_dl.getElementsByTagName('dt')[0];
		var select_lk =  select_dl.getElementsByTagName('a');
		
		
		
		for(x=0; x<select_lk.length; x++) {
			select_lk[x].onclick = function () {
				select_form.value = this.rel;
				select_dt.innerHTML = this.innerHTML;
				select_dl.style.height = '15px';
				select_dl.style.overflow = 'hidden';
				return false;
			}
		}
		
		select_dl.onmouseover = function () {
			select_dl.style.height = 'auto';
			select_dl.style.overflow = 'visible';
		} 
		select_dl.onmouseout = function () {
			select_dl.style.height = '15px';
			select_dl.style.overflow = 'hidden';
		} 

	}
	
	
	
	replaceSelectForm();		
	produktMenu ();
	produktFeatures ();
	
	
	if(typeof sIFR == "function"){

// This is the preferred "named argument" syntax
	//sIFR.replaceElement(named({sSelector:"body h1", sFlashSrc:"tradegothic.swf", sColor:"#000000", sLinkColor:"#000000", sBgColor:"#FFFFFF", sHoverColor:"#CCCCCC", nPaddingTop:20, nPaddingBottom:20, sFlashVars:"textalign=center&offsetTop=6"}));

// This is the older, ordered syntax
	
	
	//sIFR.replaceElement("#page h3.produkt_title", "flash/dinmedium.swf", "#02d7ff", null, null,transparent, 0, 0, 0, 0, null);
	sIFR.replaceElement(named({sSelector:"#page h3.produkt_title", sFlashSrc:"flash/dinmedium.swf", sColor:"#02d7ff",  sWmode:"transparent"}));

};



	function fixProduktMenu () {
		var produkt_menu = document.getElementById('produkt_menu');
		if(!produkt_menu) {return false}
		/*
    var telefone_lk = getElementsByClass('telefone_lk',produkt_menu,'a');
		if(telefone_lk.length) {
			telefone_lk = telefone_lk[0];
		}
		
		telefone_lk.setAttribute('href','http://www.grundig-dect.com');
		telefone_lk.setAttribute('target','_blank');
		telefone_lk.parentNode.className = 'produkt_menu_last';
		*/
		
		var pm_lks = getElementsByClass('pm',produkt_menu,'a');
		var produkt_sections = getElementsByClass('produkt_section',produkt_menu,'div'); 
		var close_links = [];
		
		for(x=0; x<produkt_sections.length; x++) {
			 close_links[x] = document.createElement('a');
			 close_links[x].className = 'close';
			 close_links[x].setAttribute('href','#');
			 close_links[x].setAttribute('title','Close');
			 produkt_sections[x].appendChild(close_links[x]);
			 addEvent(close_links[x],'click',function (e) {
					
					if (!e) var e = window.event
					// handle event
					if (e.stopPropagation) e.stopPropagation();
					var hovered_menu = document.getElementById('hovered_menu');
					if(hovered_menu) {
						hovered_menu.removeAttribute('id');
					}
					e.cancelBubble = true;
					if(window.event) {window.event.returnValue = false;}
					if(e.preventDefault) e.preventDefault();
					
					
			 });
			
		}
		
		
		
		
		function addEvent( obj, type, fn )
		{
			if (obj.addEventListener)
				obj.addEventListener( type, fn, false );
			else if (obj.attachEvent)
			{
				obj["e"+type+fn] = fn;
				obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
				obj.attachEvent( "on"+type, obj[type+fn] );
			}
		}
		
		function removeEvent( obj, type, fn )
		{
			if (obj.removeEventListener)
				obj.removeEventListener( type, fn, false );
			else if (obj.detachEvent)
			{
				obj.detachEvent( "on"+type, obj[type+fn] );
				obj[type+fn] = null;
				obj["e"+type+fn] = null;
			}
		}

		
		
		
		for(i=0; i<pm_lks.length; i++) {
			
			addEvent(pm_lks[i],'click',function (e) {
				
				
				
				if(this.className.indexOf('telefone_lk')<0) {
					
					if (!e) var e = window.event
					// handle event
					
					

					
					
					var hovered_menu = document.getElementById('hovered_menu');
					if(hovered_menu) {hovered_menu.removeAttribute('id')}
					this.parentNode.setAttribute('id','hovered_menu');
					hovered_menu = this.parentNode;
					e.cancelBubble = true;
					if(window.event) {window.event.returnValue = false;}
					if(e.preventDefault) e.preventDefault();
					if (e.stopPropagation) e.stopPropagation();
				}
			})
			
		}
		
		
		addEvent(document.body,'click',function (e) {
			if (!e) var e = window.event
			// handle event
			e.cancelBubble = true;
			if (e.stopPropagation) e.stopPropagation();	
			var hovered_menu = document.getElementById('hovered_menu');
			if(hovered_menu) {hovered_menu.removeAttribute('id')}
			
			var produkt_menu_wrapper_toggler = document.getElementById('produkt_menu_wrapper_toggler');
			if(produkt_menu_wrapper_toggler) {
				$('#produkt_menu_wrapper').css('display','none');
			}
			
		});
		
		
		
		
		
	}
	
	
	
	function hoverImages () {
		var produkt_menu = document.getElementById('produkt_menu');
		if(!produkt_menu) {return false}
		var produkt_lks = produkt_menu.getElementsByTagName('a');
		var arr_lks = [];
		
		for(x=0; x<produkt_lks.length; x++) {
			if(produkt_lks[x].className!='close') {
				arr_lks.push(produkt_lks[x]);	
			}
		}
		
		for(i=0; i<arr_lks.length; i++) {
			
			
			this_arr_lk = arr_lks[i];
			this_arr_lk.onmouseover = function(value) {
				return function() {
					
					var target_img = this;
				
					if(this.getAttribute('class')&&this.className.indexOf('pm')>-1) {
						target_img = getElementsByClass('produkt_section',target_img.parentNode,'div')[0];
						target_img = target_img.getElementsByTagName('img')[0];
						
					} else {
						target_img = this;
						
						while(target_img.className!='produkt_section') {
							target_img = target_img.parentNode;
						}
						target_img = target_img.getElementsByTagName('img')[0];
						
					}
					
					if(images[value]!='null') {
						target_img.setAttribute('src',images[value]);
						target_img.style.visibility = 'visible';
					}
					
					if(images[value]=='null') {
						target_img.style.visibility = 'hidden';
					}
					
				}
			}(i);
			
		}
		
	}
	
	
	
	fixProduktMenu();
	hoverImages();
	
							
});



