/*-------------------------------------------------------------------- 
 * JQuery Plugin: "EqualHeights"  by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 * Copyright (c) 2008 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 * Version: 2.0, 08.01.2008
--------------------------------------------------------------------*/

jQuery.fn.equalHeights = function(px) {
    $(this).each(function(){
        var currentTallest = 0;
        jQuery(this).children().each(function(i){
            if (jQuery(this).height() > currentTallest) {
                currentTallest = jQuery(this).height();
            }
        });
        // for ie6, set height since min-height isn't supported
        if (jQuery.browser.msie && jQuery.browser.version == 6.0) {
            jQuery(this).children().css({
                'height': currentTallest
            });
        }
        jQuery(this).children().css({
            'min-height': currentTallest
        }); 
    });
    return this;
};
/*--------------------------------------------------------------------*/


// get tab index# by its id
function getIndexForId(searchId){
    var index = -1 //if function returns -1, then tab wasn't found

    jQuery("div.tab-content").each(function(){
        if (jQuery(this).attr("id") == searchId){
            index = jQuery("#tabs .tab-content").index(this);
        }            
    });
    return index
}



// increase / decrease cart qty
function increase(input) {
    document.getElementsByName(input)[0].value = parseInt(document.getElementsByName(input)[0].value)+1;
    return false
}

function decrease(input) {
    var elementD = document.getElementsByName(input)[0].value;
    if(elementD > 1) {
        document.getElementsByName(input)[0].value = elementD-1   
    }    
    return false
}

/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
            ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) {
        return s;
    } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};




jQuery(document).ready(function() {
  
    // reset scrollbar
    // to do: verify if this is really desirable!
    jQuery.scrollTo( 0 );
  
    // product view tabs
    if(jQuery(".product-view #tabs").length){
        jQuery( "#tabs" ).tabs(); 
    }     
  
  
    // account-registration
    if(jQuery(".col2-set .new-users").length > 0 && jQuery(".col2-set .registered-users").length > 0) {
        jQuery(".col2-set:first").addClass("surrounding");    
        jQuery(".surrounding").equalHeights();    
    }
    
    
    // checkout
    if(jQuery(".multiple-checkout #multiship-addresses-table").length > 0) {        
        jQuery('.multiple-checkout h2').click(function() {
            jQuery('#multiship-addresses-table').toggle();
            jQuery(this).toggleClass("active");
        });        
    }    
    if(jQuery(".cart-collaterals").length > 0) {
        jQuery(".cart-collaterals .totals tfoot tr:last").addClass("totalSum");
        
        jQuery("#shopping-cart-totals-table tbody tr:first").addClass("firstrow");
        jQuery("#shopping-cart-totals-table tbody tr:not(:first)").children("td:first").prepend("+");
    }
    
    
    // main navigation first level
    
    // is shop active?
    jQuery("#nav_custom li.first-level > a").click(function(){
        jQuery("#nav_custom li").removeClass("active");
        jQuery(this).parent("li").addClass("active load");
        jQuery(this).parent("li").parent("#nav").removeClass();
        jQuery(this).parent("li").parent("#nav").addClass("shop");
    });
    
    // is freelend active?
    jQuery("#nav_custom li.kostenlose-geraeteleihe > a").click(function(){
        jQuery("#nav_custom li").removeClass("active");
        jQuery(this).parent("li").addClass("active load");
        jQuery(this).parent("li").parent("#nav").removeClass();
        jQuery(this).parent("li").parent("#nav").addClass("freelend");
    });
    
    // is smartrent active?
    jQuery("#nav_custom li.clevermiete > a").click(function(){
        jQuery("#nav_custom li").removeClass("active");
        jQuery(this).parent("li").addClass("active load");
        jQuery(this).parent("li").parent("#nav").removeClass();
        jQuery(this).parent("li").parent("#nav").addClass("smartrent");
    });
    
    // is about us active?
    jQuery("#nav_custom li.mitarbeiter > a").click(function(){
        jQuery("#nav_custom li").removeClass("active");
        jQuery(this).parent("li").addClass("active load");
        jQuery(this).parent("li").parent("#nav").removeClass();
        jQuery(this).parent("li").parent("#nav").addClass("aboutus");
    });
    
    jQuery("#nav_custom li.first-level.active").parent("#nav").addClass("shop");
    jQuery("#nav_custom li.kostenlose-geraeteleihe.active").parent("#nav").addClass("freelend");
    jQuery("#nav_custom li.clevermiete.active").parent("#nav").addClass("smartrent");
    jQuery("#nav_custom li.mitarbeiter.active").parent("#nav").addClass("aboutus");
    
    
    // main nav second level
    
    if(jQuery("#nav_custom li ul").length > 0) {
        jQuery("#nav_custom li ul li:first-child").addClass("first");
        jQuery("#nav_custom li ul li:last-child").addClass("last");
    }
    
    if(jQuery("#nav_custom li ul").length > 0) {
        var fL = jQuery("#nav_custom li ul li a.active");
        jQuery(fL).parent("li").addClass("active");
        jQuery(fL).parent("li").parent().parent("li").addClass("active");
    }
    
    
    
    // navigation left
    jQuery("#narrow-by-list2 .child:last").addClass("last");
    jQuery("#narrow-by-list2 .child:first").addClass("first");
    
    
    // filter expandable in layered navigation
    jQuery("#narrow-by-list dd").hide();
    jQuery("#narrow-by-list dt").click(function() {
        jQuery(this).next("dd").toggle();
        jQuery(this).toggleClass("active");
    });
    
    
    // lightbox for sendtofriend form
    jQuery("a[rel=fancybox-sendfriend]").fancybox({
        type: 'inline',
        autoDimensions: false,
        width: 680,
        height: 490
    });  
        
        
    // lightbox for error reporting form
    jQuery("a[rel=fancybox-bugreport]").fancybox({
        type: 'inline',
        autoDimensions: false,
        width: 680,
        height: 460
    });  
    
    // lightbox for callback form
    jQuery("a[rel=fancybox-callback]").fancybox({
        type: 'inline',
        autoDimensions: false,
        width: 680,
        height: 580
    });  
        
    // smooth scroll for more details link
    jQuery(".more-info").click(function() {
        jQuery("#tabs").tabs('select', 0);
        jQuery.scrollTo('#tab-details', 800,{offset:-50});            
        return false;
    });
    
        
    // footercols equalheights
    var height1 = jQuery(".footer .fcol3").height();
    var height2 = jQuery(".footer .fcol4").height();
        
    if(height1<height2){
        height1 = height2;            
    }
    jQuery(".footer .fcol3").height(height1);
    jQuery(".footer .fcol4").height(height1);
                
    

    // product list positioning of vat-disclaimer
    jQuery(".vat-disclaimer").prev(".tier").each(function() {
        jQuery(this).next(".vat-disclaimer").appendTo(jQuery(this));
        jQuery(this).next(".vat-disclaimer").remove();
    });
    
    // product list positioning of vat-disclaimer
    jQuery(".category-products .vat-disclaimer").each(function() {        
        jQuery(this).appendTo(jQuery(this).prev(".price-box").children(".regular-price"));
    });
    
    
    // product list positioning of sales-unit
    jQuery(".sales-unit").prev(".tier").each(function() {
        jQuery(this).next(".sales-unit").appendTo(jQuery(this));
        jQuery(this).next(".sales-unit").remove();
    });
    
    // product list positioning of vat-disclaimer
    jQuery(".category-products .sales-unit").each(function() {        
        jQuery(this).appendTo(jQuery(this).prev(".price-box").children(".regular-price"));
    });
    
    
    // related product list positioning of vat    
    jQuery("#tab-related .vat-disclaimer").each(function() {
        jQuery(this).appendTo(jQuery(this).prev(".price-box > .regular-price"));
    });
    
    // compare product list positioning of vat    
    jQuery(".catalog-product-compare-index .vat-disclaimer").each(function() {       
        jQuery(this).prev(".price-box").children(".regular-price").append(jQuery(this));
    });
     
    
    // pager-function for content
    if(jQuery(".sheet-container").length) {
              
        jQuery(".sheet-container div.sheet:not(:first)").hide();
        jQuery(".sheet-container div.sheet:not(:first)").children().hide();
        jQuery(".sheet-container div.nav-elements:not(:first)").hide();
       
        jQuery(".sheet-container div.nav-elements span.next").live("click", function() {                    
            jQuery(this).parent().prev("div.sheet").hide();
            jQuery(this).parent().hide();          
            jQuery(this).parent().next("div.sheet").show();          
            jQuery(this).parent().next("div.sheet").children().fadeIn();          
            jQuery(this).parent().next("div.sheet").next("div.nav-elements").show(0);          
          
        });
       
        jQuery(".sheet-container div.nav-elements span.prev").live("click", function() {                    
            jQuery(this).parent().prev("div.sheet").hide();
            jQuery(this).parent().hide();          
            jQuery(this).parent().prev("div.sheet").prev("div.nav-elements").prev("div.sheet").show();          
            jQuery(this).parent().prev("div.sheet").prev("div.nav-elements").prev("div.sheet").children().fadeIn();          
            jQuery(this).parent().prev("div.sheet").prev("div.nav-elements").show(0);     
          
        });  
    }
    
    // contact form switch telephone/email contact
    if(jQuery(".contact-select").length) {
        
        //jQuery(".contact-select .input-box input").attr("disabled").addClass("disabled");
        
        jQuery(".contact-select :radio").change(function() {
            
            if(!jQuery(this).hasClass("selected")) {
                
                jQuery(".contact-select .input-box input").attr('readonly', false).removeClass("disabled");
                jQuery(".contact-select .input-box input").not(jQuery("input."+jQuery(this).attr("id"))).attr('readonly', true).addClass("disabled");
                
                if(jQuery(this).hasClass("email-select")) {
                    jQuery(".contact-select .input-box input.email-select").addClass("required-entry");
                    jQuery(".contact-select .input-box input.email-select").addClass("validate-email");
                    
                    jQuery(".contact-select .input-box input.telephone-select").removeClass("required-entry");                    
                    
                }
                
                if(jQuery(this).hasClass("telephone-select")) {
                    jQuery(".contact-select .input-box input.email-select").removeClass("required-entry");
                    jQuery(".contact-select .input-box input.email-select").removeClass("validate-email");
                    
                    jQuery(".contact-select .input-box input.telephone-select").addClass("required-entry");                    
                    
                }
                
                
                jQuery(".contact-select :radio").removeClass("selected");
                jQuery(this).addClass("selected");
                    
            }
            
        });
    }
    
    // linkage for whole cart-block in header
    jQuery(".nav-container .block-cart").click(function() {
        window.location.href = "/checkout/cart/" 
    });
    
    // faq tab foldouts
    jQuery("#tab-faq h4").live("click", function(e) {
           
        if(jQuery(this).hasClass("active")) {
            jQuery(this).next("p.answer").hide();
            jQuery(this).removeClass("active");
            return false
        }
           
        jQuery(this).next("p").show(300);
        jQuery(this).addClass("active");
        return false
            
    });
    // -- faq tab foldouts

    
    // messages    
    if(jQuery("ul.messages").length > 0) {
        jQuery("ul.messages li:first").addClass("first");
        jQuery("ul.messages li.first").prepend('<span class="close">&nbsp;</span>').click(function(){
            jQuery(this).fadeOut(300); 
        });
    }

    // move position of pager in supply view
    jQuery(".supplies-search-result .pager .limit").each(function() {
        jQuery(this).parent().next().children(".pages").appendTo(jQuery(this));
        jQuery(this).parent().next().children(".pages").remove();
    }) 

    // product view even odd table rows
    jQuery("#product-attribute-specs-table tr:even").addClass("even");    


    // init fancybox
    jQuery("a.fancybox").fancybox();


    // newsletter subscription clean input
    jQuery('input#newsletter').focus(function() {
        if(jQuery(this).attr("value") == "Ihre Email-Adresse") {
            jQuery(this).attr("value", "");
        } 
    });

    jQuery('input#newsletter').blur(function() {
        if(jQuery(this).attr("value") == "") {
            jQuery(this).attr("value", "Ihre Email-Adresse");
        } 
    });


    // newsletter subscription change
    jQuery(".newsletter-manage-index ul.form-list li input:radio").change(function() {

        if(jQuery(this).attr("id") == 'sub1' || jQuery(this).attr("id") == 'sub2'|| jQuery(this).attr("id") == 'sub3' ) {
            jQuery("input#abo2").removeAttr('checked');
            jQuery("input#abo1").attr('checked', "checked");                                    
        }
        
        if(jQuery(this).attr("id") == 'abo2' ) {
            jQuery("input#sub1").removeAttr('checked');
            jQuery("input#sub2").removeAttr('checked');
            jQuery("input#sub3").removeAttr('checked');
        }


    });
    
    // option for target blank w/o risking w3c conformity
    jQuery("a._blank").attr("target", "_blank");

    // sonderposten category: no link to parent category
    jQuery(".category-alle-artikel .block-layered-nav-top a").css("cursor","default");
    jQuery(".category-alle-artikel .block-layered-nav-top a").click(function() {
        return false
    });
    
    // cart: dont display minus in front of catalog rule
    jQuery("#shopping-cart-totals-table tbody td.a-right").each(function() {
       jQuery(this).html(jQuery(this).html().replace(/\+/, "&nbsp;")); 
    });


    // ie 6 warning
    var IE6 = (navigator.userAgent.indexOf("MSIE 6")>=0) ? true : false;
    var ffOld = (jQuery.browser.mozilla && parseInt(jQuery.browser.version,10) < 3) ? true : false;
  
  if((IE6 && !jQuery.cookie('hasseen')) || ffOld && !jQuery.cookie('hasseen')) {   
    
        jQuery("<div>")
        .css({
            'position': 'absolute',
            'top': '0px',
            'left': '0px',
            backgroundColor: 'black',
            'opacity': '0.75',
            'width': '100%',
            'height': jQuery("body").height(),
            zIndex: 5000
        })
        .appendTo("body");

        var c1 = '<p><br />Sehr geehrte Kundin, sehr geehrter Kunde,</p>'
        var c2 = '<p>Sie nutzen eine sehr alte Browser-Version des Microsoft Internet Explorer / Mozilla Firefox:<br /><br />- Diese werden von den Herstellern nicht mehr mit Sicherheits-Updates unterstützt und sind daher für Sie risikoreich.<br />- Überdies kann es bei diesen alten Browsern zu Fehldarstellungen / Fehlfunktionen in unserem Shop kommen. Auch kann die Geschwindigkeit sehr, sehr langsam sein.</p>'
        var c3 = '<p>Daher empfehlen wir Ihnen: Laden Sie die aktuelle Version Ihres Browsers herunter.<br />Dazu verweisen wir hier auf die Downloadseite des Herstellers von wo Sie die aktuellste Version des Browsers kostenfrei herunterladen können. (Unsere Empfehlung ist keine Werbung sondern soll Ihnen die Nutzung unseres Shops so sicher und bequem wie möglich machen):</p>'

        var b1 = '<table>';;
        var b2 = '<tr><td><a target="_blank" href="http://www.microsoft.com/windows/Internet-explorer/default.aspx"><img src="/skin/frontend/pro/alpha/images/ie_25.jpg" alt="Internet Explorer" /></a></td><td><a target="_blank" href="http://www.microsoft.com/windows/Internet-explorer/default.aspx" style="font-weight:bold">Microsoft Internet Explorer</a><br /><a target="_blank" href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">http://www.microsoft.com/windows/Internet-explorer/default.aspx</a></td></tr>';
        var b3 = '<tr><td><a target="_blank" href="http://www.mozilla.com/firefox/"><img src="/skin/frontend/pro/alpha/images/ff_25.jpg" alt="Mozilla Firefox" /></a></td><td><a target="_blank" href="http://www.mozilla.com/firefox/" style="font-weight:bold">Mozilla Firefox</a><br /><a target="_blank" href="http://www.mozilla.com/firefox/">http://www.mozilla.com/firefox/</a></td></tr>';
        var b4 = '</table>';
        var b5 = '<p style="clear:both"><br />Sollten Sie <a href="#" onclick="jQuery(this).parent().parent().hide(); jQuery(this).parent().parent().prev().hide(); return false"><u>www.alpha-buerobedarf.de</u></a> dennoch weiterhin mit Ihrem veralteten Browser nutzen wollen (es kann zu Fehldarstellungen und langsamer Geschwindigkeit kommen) <a href="#" onclick="jQuery(this).parent().parent().hide(); jQuery(this).parent().parent().prev().hide(); return false"><u>klicken Sie bitte hier</u></a>.<br /><br />Wir hoffen Ihnen mit diesen Informationen geholfen zu haben<br />Ihr alpha Online-Team<br /><br /></p>';

        var connected = c1 + c2 + c3 + b1 + b2 + b3 + b4 + b5;
        var close = '<div><img src="/skin/frontend/pro/alpha/images/btn_remove.gif" style="cursor:pointer; float:right" alt="schließen" onclick="jQuery(this).parent().parent().hide(); jQuery(this).parent().parent().prev().hide()" /></div>';
            
        jQuery("<div class='browserwarning'>"+ close + connected +"</div>")
        .css({
            backgroundColor: 'white',
            'top': '50%',
            'left': '50%',
            marginLeft: -320,
            marginTop: -150,
            width: 640,
            padding: 15,
            height:400,
            textAlign : 'left',
            'position': 'absolute',
            zIndex: 6000
        })
        .appendTo("body");        
            
            
        jQuery.cookie('hasseen','1');
   }


    // customer cart disclaimer
        
       jQuery("#cartinfo_link").fancybox({
            type: 'inline',
            autoDimensions: false,
            width: 600,
            height: 250
       });  
        
       jQuery("#cartinfo_link").trigger('click');
        
            

// end document-ready
});



