
jQuery(document).ready(function() {
    
    // smartrent cms
    
    //jQuery("a.detail").fancybox();
    
    if(jQuery(".smartrent-products").length > 0) {
        
        jQuery(".smartrent-products-list").each(function() {
            height = 0;
                    
            jQuery(this).find("a.product-name").each(function() {                    
                if(jQuery(this).height() > height) {
                    height = jQuery(this).height();
                } 
            });
                    
            jQuery(this).find("a.product-name").each(function() {                    
                jQuery(this).height(height);
            });
        });
            
            
        jQuery(".smartrent-products-list").each(function() {
            jQuery(this).equalHeights();            
        });
        
        jQuery(".smartrent-products-list li").each(function() {
            jQuery(this).children(".product").height(jQuery(this).height());            
        });
        
        

// foldout in cms view
        
        jQuery(".smartrent-products").hide();
        
        jQuery("h3.smartrent").click(function() {
            jQuery(".smartrent-products").hide(200);
            if(!jQuery("span", this).hasClass("active")) {
                jQuery("h3.smartrent span").removeClass("active");
                jQuery("h3.smartrent span").addClass("inactive");
                jQuery("span", this).removeClass("inactive");
                jQuery("span", this).addClass("active");
                jQuery(this).next(".smartrent-products").show(300);            
            } else {                
                jQuery("span", this).removeClass("active");
                jQuery("span", this).addClass("inactive");
                jQuery(this).next(".smartrent-products").hide(200);            
            }
        });   
        
    }
       
    
    // smartrent product view
    if(jQuery("div#tab-rent").length > 0) {
        
        // get index of the rent-tab
        tabrentid = getIndexForId("tab-rent");   
        
        // if button at the top is clicked, scroll down to tab and open it
        jQuery(".btn-rent").click(function() {
            jQuery("#tabs").tabs('select', tabrentid);
            jQuery.scrollTo( '#tab-rent', 800,{offset:-50});            
            return false;
        });
        
        // in-text popups
        jQuery("span.popup-span").prepend('<span class="close">&nbsp;</span>').click(function(){
                jQuery(this).fadeOut(300); 
            });
        jQuery("span.popup-span").each(function() {
            jQuery(this).attr("height", jQuery(this).height());
        });
        
        jQuery("span.popup-span").hide();
        
        jQuery("a.popup-span").live("click", function(e) {

            // close container if it's already active
            if(jQuery(this).hasClass("active")) {
                jQuery(this).removeClass("active");
                jQuery(this).next("span.popup-span").hide();
                return false;
            }
            
            // close existing containers
            jQuery(".popup-active").hide();
            jQuery(".popup-active").removeClass("popup-active");


            // make the following container active
            jQuery(this).next("span.popup-span").addClass("popup-active");

            
            jQuery(this).next("span.popup-span").show();

            // position container
            conheight = 0;
            conheight = jQuery(this).next("span.popup-span").height()/2;

            position = jQuery(this).position();
            positionY = position.top-conheight;
            positionX = position.left+jQuery(this).width()+40;
            
            // positioning of popup
            jQuery(".popup-active").css("top", positionY+"px");
            jQuery(".popup-active").css("left", positionX+"px");
      
            jQuery(".popup-active .popout-left").css({
                "left":"-20px", 
                "top":conheight-3
            });          
            jQuery(this).addClass("active");
                        
            return false;
        });
        
        // -- in-text popups
        
        // in-text foldouts
        jQuery("a.foldout").live("click", function(e) {
           
            if(jQuery(this).hasClass("active")) {
                jQuery(this).next("p.foldout").hide();
                jQuery(this).removeClass("active");
                return false
            }
           
            jQuery(this).next("p.foldout").show(300);
            jQuery(this).addClass("active");
            return false
            
        });
        // -- in-text foldouts
        
        
        jQuery("#quickorder-rent").submit(function() {            
            
            if($F('accept-agreement')==null) {
                alert("Bitte stimmen Sie den Vertragsbedingungen zu!");
                return false;
            }
            else {
                return true
            }
        });
    }    
    // end if smartrent-product view
    
});
