jQuery(document).ready(function () 
{
	
  handleSearchbox();
  handleSubNav();
  
  if (bol_isIE && (bol_isIE6 || bol_isIE7))
  {
    handleIE6FormElements();
  }
  
  includePrintLink();
/**
 * Tooltips
 */
  if($('.tooltip').length > 0){
	$('.tooltip').tooltip({
		delay: 0,
		showURL: false,
		showBody: '' 
	});
  }
  
  	/**
   	* Eventtracking for tip a friend
   	*/ 
    $('input[name=tx_pmtipafriend_pi1[submit]]').click(function(){
    	//extract only url
    	var fullUrl =$('input[name=tx_pmtipafriend_pi1[tipUrl]]').val(); 
    	var splittedFullUrl = fullUrl.split("oelheizung.info");
  	    ET_Event.eventStart('Weiterempfehlen', splittedFullUrl[1], 'Weiterempfehlen', 'Weiterempfehlen');
  	    return true;
    });

   /**
   	* Eventtracking for Downloads
   	*/ 
	/* Removed eTracker Event-Tracking Debugging */
	$('.mediathek_downloads a[href], .download_page a[href]').click(function(evt){
  		var tempDoc = $(this).attr('href');
		var doc = ''+$(this).attr('href')+'';
		if(doc.lastIndexOf('/') >= 0)
		  doc = doc.substring( doc.lastIndexOf('/')+1 );
		
		ET_Event.download(doc,'Medathek%2C%20Download');

      	if(typeof(evt.preventDefault) == 'function')
        	evt.preventDefault();		


		window.setTimeout(function() {
          window.location.href= 'http://' + window.location.host + '/' + tempDoc; }, 500);		
		//ET_Event.download('Medathek%2C%20Download', ''+$(this).attr('href')+'', 'Medathek%2C%20Download', 'Medathek%2C%20Download');
		return true;
    });

	/* Source-Code provided by eTracker	
    $('.mediathek_downloads a[href], .download_page a[href]').click(function(evt){
    
                    if(typeof(evt.preventDefault) == 'function')
                                    evt.preventDefault();
                                    
                    var doc = ''+$(this).attr('href')+'';

                    if(!$(this).attr('title'))
                                    $(this).attr('title', doc);
                    $(this).attr('href', 'javascript:void(0);');

                    if(doc.lastIndexOf('/') >= 0)
                                    doc = doc.substring( doc.lastIndexOf('/')+1 );

                    ET_Event.download(doc,'Mediathek%2C%20Download');
                    
					
					window.setTimeout("document.location = $(this).attr('title')", 500);

                    return true;        
    });*/

});


/**
 * function handleSearchbox()
 *
 * Set the default text, if no user input is inside the input field 
 */
function handleSearchbox() 
{
  // On focus, delete default text if available
  jQuery("#quickSearch input[name=searchterm]").focus(function()
  {
    if (jQuery("#quickSearch input[name=searchterm]").val() == 'Suchbegriff eingeben') 
    {
      jQuery(this).val('');
    } 
  });
  
  // On blur, set default text if value is empty
  jQuery("#quickSearch input[name=searchterm]").blur(function()
  {
    if (jQuery("#quickSearch input[name=searchterm]").val() == '') {
      jQuery(this).val('Suchbegriff eingeben');
    }
  });
  
  // Set focus to search input filed on startup 
  jQuery("#quickSearch input[name=searchterm]").focus();
}


/**
 * function handleSubNav()
 *
 * Handle the behavior of the subnavigation menu 
 */
function handleSubNav() 
{
  // Close all list elements
  jQuery(".subnavigation ul").addClass("closed");
  jQuery(".subnavigation li.hasSubparts a").addClass("closed");
  
  // Open current path
  jQuery(".subnavigation li.current").each(function() 
  {
    if (jQuery(this).hasClass("hasSubparts"))
    {
      jQuery(this).children("a:first").removeClass("closed");
      jQuery(this).children("ul").removeClass("closed");
    }
  });
  
  // Bind 'onclick' functionality to a tags. 
  /*
  jQuery(".subnavigation li.hasSubparts a").click(function() 
  {
    jQuery(this).toggleClass("closed");
    jQuery(this).next("ul").toggleClass("closed");
    
    return false;
  });
  */
}


/**
 * function handleIE6FormElements()
 *
 * Handle the behavior form elements for IE6.
 * Set / Remove .hover and .focus class
 */
function handleIE6FormElements() 
{
  jQuery("input, select, textarea").blur(function() 
  {
    jQuery(this).removeClass("focus");
  });
  jQuery("input, select, textarea").focus(function() 
  {
    jQuery(this).addClass("focus");
  });
  
  jQuery("input, select, textarea").hover(function() 
  {
    jQuery(this).addClass("hover");
  },
  function()
  {
    jQuery(this).removeClass("hover");
  });
}
 

/**
 * function includePrintLink()
 *
 * Include the print Page link to all '.printPage' elements
 */
function includePrintLink() 
{
  //jQuery(".printPage").html('<strong>Artikel drucken</strong>');
  jQuery(".printPage strong").click(function() 
  {
    window.print();
    return false;
  });
}
