/**
 * Startet jQuery-Plugins
 */
 
 	/*
	function megaHoverOver(){
	    jQuery(this).find(".sub").stop().fadeTo('fast', 1).show(); //Find sub and fade it in
	    (function($) {
	        //Function to calculate total width of all ul's
	        jQuery.fn.calcSubWidth = function() {
	            rowWidth = 0;
	            //Calculate row
	            jQuery(this).find("ul").each(function() { //for each ul...
	                rowWidth += jQuery(this).width(); //Add each ul's width together
	            });
	        };
	    })(jQuery); 
		
	    if ( jQuery(this).find(".row").length > 0 ) { //If row exists...
			
	        var biggestRow = 0;	
			
	        jQuery(this).find(".row").each(function() {	//for each row...
	            jQuery(this).calcSubWidth(); //Call function to calculate width of all ul's
	            //Find biggest row
	            if(rowWidth > biggestRow) {
	                biggestRow = rowWidth;
	            }
	        });
			
	        jQuery(this).find(".sub").css({'width' :biggestRow}); //Set width
	        jQuery(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin
			
	    } else { //If row does not exist...
			
	        jQuery(this).calcSubWidth();  //Call function to calculate width of all ul's
	        jQuery(this).find(".sub").css({'width' : rowWidth}); //Set Width
			
	    }
	}
	//On Hover Out
	function megaHoverOut(){
	  jQuery(this).find(".sub").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
	      jQuery(this).hide();  //after fading, hide it
	  });
	}
	*/

jQuery(document).ready(function(){
	
	var tabs ;
	
	/* Tabs */
	if( jQuery(".product-collateral").length ){
		
		jQuery.getScript("/js/jquery/tabs/jquery.tabs.js", function(){
			jQuery.getScript("/js/jquery/jquery.syncheight.js", function(){
				
				tabs = jQuery(".product-collateral").accessibleTabs({fx:"show",fxspeed: '', syncheights: true, tabhead:'h2.tab', tabbody:'.box-collateral'});
			});
		});
		
       jQuery("a[href=#reviewtab]").click(function(e){
            //e.preventDefault();
            tabs.showAccessibleTab(3);
        });
 	}

	/* Slider */
	if( jQuery(".horinaja").length ){
		
		a = document.createElement('link') ;
		a.setAttribute('rel','stylesheet') ;
		a.setAttribute('type','text/css') ;
		a.setAttribute('href','/js/jquery/horinaja/horinaja.css') ;
		document.getElementsByTagName('head')[0].appendChild(a) ;
		
	}
	
	/* Promoslider */
	if( jQuery("#promoslider").length ){
		/*
		jQuery.getScript("/js/jquery/jquery.bxslider2.0.1.min", function(){
		});
		*/
 	}

	/* Quantity-changer */
	jQuery( function() {
		jQuery("#qty").after('<a href="#" onclick="return false;"><div class="qtyinc qtybutton"></div></a><a href="#" onclick="return false;"><div class="qtydec qtybutton"></div></a>') ;
	});	
	jQuery(".qtyinc").click(function() {
	    
		var jQuerybutton = jQuery(this);
		var oldValue = jQuery("input#qty").val();
    	var newVal = parseFloat(oldValue) + 1;
		jQuery("input#qty").val( newVal ) ;
	});
	jQuery(".qtydec").click(function() {
	    
		var jQuerybutton = jQuery(this);
		var oldValue = jQuery("input#qty").val();
	  	if (oldValue >= 2) {
		  var newVal = parseFloat(oldValue) - 1;
	  	}
		jQuery("input#qty").val( newVal ) ;
	});
	jQuery(function() {
		
	    jQuery("#qty").bind("mousewheel", function(event, delta) {
	        if (delta > 0) {
	            this.value = parseInt(this.value) + 1;
	        } else {
	            if (parseInt(this.value) > 1) {
	                this.value = parseInt(this.value) - 1;
	            }
	        }
	        return false;
	     });
	});

	/* Mengenstaffeln in den warenkorb */
	jQuery(".qtytocart").click(function() {
		var anzahl = jQuery(this).attr("rel") ;
		jQuery("input#qty").val( anzahl ) ;
		jQuery(".add-to-cart button.btn-cart").trigger("click") ;
		return false ;
	}) ;

/* Ländercheck beim Cehckout -> Telefonpflicht */

	jQuery("select#country").change(function() {
		cc = jQuery(this).attr("value") ; if ( cc != "DE" ) { jQuery("#rcadresstelephone" ).html(" *") ; } else { jQuery("#rcadresstelephone" ).html("") ; }
	});
	jQuery("#buttoncadresssave").click(function() {
		cc = jQuery("select#country").attr("value") ; phone = jQuery("#telephone").attr("value") ;
		if ( cc != "DE" && phone == "" ) { alert ( "Bitte geben Sie bei Bestellungen aus dem Ausland eine Telefonnummer an. Diese ist laut DHL-Bestimmungen zwingend erforderlich." ) ; return false ; } else { return; }
				
	});

	jQuery("select#billing\\:country_id").change(function() {
		cc = jQuery(this).attr("value") ; if ( cc != "DE" ) { jQuery("#rbillingtelephone" ).html(" *") ; } else { jQuery("#rbillingtelephone" ).html("") ; }
	});
	jQuery("#butonbillingsave").click(function() {
		cc = jQuery("select#billing\\:country_id").attr("value") ; phone = jQuery("#billing\\:telephone").attr("value") ;
		if ( cc != "DE" && phone == "" ) { alert ( "Bitte geben Sie bei Bestellungen aus dem Ausland eine Telefonnummer an. Diese ist laut DHL-Bestimmungen zwingend erforderlich." ) ; return false ; } else { billing.save() ; }
				
	});

	jQuery("select#shipping\\:country_id").change(function() {
		cc = jQuery(this).attr("value") ; if ( cc != "DE" ) { jQuery("#rshippingtelephone" ).html(" *") ; } else { jQuery("#rshippingtelephone" ).html("") ; }
	});
	jQuery("#butonshippingsave").click(function() {
		cc = jQuery("select#shipping\\:country_id").attr("value") ; phone = jQuery("#shipping\\:telephone").attr("value") ;
		if ( cc != "DE" && phone == "" ) { alert ( "Bitte geben Sie bei Bestellungen aus dem Ausland eine Telefonnummer an. Diese ist laut DHL-Bestimmungen zwingend erforderlich." ) ; return false ; } else { shipping.save() ; }
				
	});

	/* Analytics-Aktionen */
	jQuery("#showwebflyer").click(function() {
		_gaq.push(['_trackEvent', 'Userklicks', 'Werbegrafiken', 'Sidebar Webflyer']);
		return ;
	}) ;

	/* Mega Dropdown */

	/*
	var config = {
	     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
	     interval: 100, // number = milliseconds for onMouseOver polling interval
	     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
	     timeout: 500, // number = milliseconds delay before onMouseOut
	     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
	};
	
	jQuery("ul#nav li .sub").css({'opacity':'0'}); //Fade sub nav to 0 opacity on default
	jQuery("ul#nav li").hoverIntent(config); //Trigger Hover intent with custom configurations
	*/

});

function toggleMenu () { return; }

function opendeliciouswindow () {
	window.open('http://www.delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550');
	return false ;
}

/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmarksite(title,url){

if(window.chrome) {
    alert('Zum bookmarken einfach oben auf den Stern in der Adresszeile klicken oder Strg-D drücken!')
}

if(window.sidebar){
    // Mozilla Firefox Bookmark
    window.sidebar.addPanel(title, url,"");
    return false;
  } else if(window.external){
    // IE Favorite
    window.external.AddFavorite( url, title);
    return false;
  } else if(window.opera && window.print){
    //Opera Hotlist
    obj.setAttribute('href',url);
    obj.setAttribute('title',title);
    obj.setAttribute('rel','sidebar');
    obj.click();
    return false;
  }


}

