/**
 * Common Functions
 */
var Common = {
		
	Printer:  {
		init: function() {
			// Init all print start buttons for iframes
			if( $('.printIframe').size() > 0 ) {
				$('.printIframe').click( function(e){
				  var name = this.id;
					Common.Printer.printIframe(name);
				} );
			}
		},
	
		print: function() {
			window.print();
		},
		
		/**
		 * Print an iframe by given NAME Attribut
		 * @param string iframeName 
		 */
		printIframe: function( iframeName ) {
			var printIframe = top.frames[iframeName];
			printIframe.focus();
			printIframe.print();
		}
	},
	    
    /**
     * Class for Input Elements with Default Texts and styles
     * 
     * NOTE: if the form elements value is empty its default text and styl will be set onload
     * if not, it may be a initial text with data of the customer, so it will not be overwritten.
     * 
     * @param jQueryObejct inputElement
     * @param string defaultText
     * @param object defaultTextStyles
     * @param object normalStyles
     */
    InputDefaultText: function( inputElement , defaultText , defaultTextStyles , normalStyles ) {
    	this.inputElement = inputElement;
    	this.defaultText = defaultText;
    	this.defaultTextStyles = defaultTextStyles;
    	this.normalStyles = normalStyles;
    	
    	this.init = function() {
    		var self = this;
    		if( this.inputElement.val() == '' ) {
    			this.inputElement.val( self.defaultText );
    			this.inputElement.css( self.defaultTextStyles );
    		}    		
    		this.inputElement.focus( function() {
    			if( $(this).val() == self.defaultText ) {
    				$(this).val( '' );
    				$(this).css( self.normalStyles );
    			}
    		});
    		
    		this.inputElement.blur( function() {
    			if( $(this).val() == '' ) {
    				$(this).val( self.defaultText  );
    				$(this).css( self.defaultTextStyles );
    			}
    		});
    	};
    },
	
	/**
	 * simple switch method, you can set optionally
	 * first param as id for element to be hidden 
	 * and/or set optionally second param as id for
	 * lement to be shown
	 * @param jQueryDOMElement off
	 * @param jQueryDOMElement on
	 */
	simpleDisplaySwitch: function ( off , on ) {
		off = off !== undefined ? off : null;
		on = on !== undefined ? on : null;
		
		if( off != null && off.size() > 0 ) {
			off.hide();
		}
		if( on != null && on.size() > 0 ) {
			on.show();
		}
	},
	
	
	/**
	 * simople Wrapper for document.getElementById
	 * @param string id
	 * @return DOMObject
	 */
	element: function ( id ) {
		return document.getElementById( id );
	},
		
	/**
	 * Adobes recommended method to get SWFs as Object,
	 * to be used if SWFObjects Method can not be used
	 * @param movieName the id og the object tag
	 * @return DOMObject 
	 */
	getSWFMovie: function( movieName ) {
		if (navigator.appName.indexOf("Microsoft") != -1) {
			return window[movieName];
		} else {
			return document[movieName];
		}
	},
		
    /**
	 * popup wrapper for new Page, cause XHTML has no target attt anymore
	 * @param string url
	 * @return bool
	 */
	popup: function( url ) {
	    var win = window.open(url);
	    return false;
	}, // end popup
    
    
    /** 
     * returns an object with width and height
     * properties of the current visible area of the page
     * @return object
     */
    getViewportDimensions:function() {
       var intH = 0, intW = 0;
       
       if(self.innerHeight) {
          intH = window.innerHeight;
          intW = window.innerWidth;
       } 
       else {
           if(document.documentElement && document.documentElement.clientHeight) {
               intH = document.documentElement.clientHeight;
               intW = document.documentElement.clientWidth;
           }
           else {
               if(document.body) {
                   intH = document.body.clientHeight;
                   intW = document.body.clientWidth;
               }
           }
       }
       return {
           height: parseInt(intH, 10),
           width: parseInt(intW, 10)
       };
    },// getViewportDimensions
    
    
    /**
     * Thickbox FUnctions
     */
    Thickbox: {
    	
    	/**
    	 * the currently opened thckbox becomes an array of
    	 * the arguments which has to given on opening and 
    	 * closing in order to switch from one thickbox to the other
    	 * @var array currentThickbox
    	 */
    	currentThickbox: null,
    	
    	/**
    	 * Initialization of Thickbox opener
    	 * all hrefs with a class "thickbox" 
    	 * get a click handler which opens the 
    	 * thickbox by name
    	 * 
    	 *  opener with the additional class 'allowActionBox'
    	 *  open thickboxes which allow to use the actionbox above the 
    	 *  overlay
    	 */
    	init: function() {
    		var self = this;
    		
    		$('.thickbox').click( function() {
    			var tbTitle = null;
    			var tbName = $( this ).attr('href');
    			tbName = tbName.split( '#' )[1];
    			if( tbName.indexOf( '|' ) != -1 ) {
    				tbTitle = tbName.split( '|' )[1];
    				tbName = tbName.split( '|' )[0];   				
    			}
    			var allowActionbox  = $( this ).hasClass( 'allowActionBox' ); 
    			var allowScroll = $( this ).hasClass( 'allowScroll' );
    			self.openThickbox( tbName , tbTitle , allowActionbox , allowScroll );
    			return false;
    		} );
    	},
    	
    	
    	/**
    	 * open a Thickbox by given Name
    	 * the content is to be opened and calles as
    	 * var tbContent = $('#content_thickbox_'+elementName);
    	 * this content div is arranged with others in one of the template divs
    	 * The third Param switches the overlays z-index down to 79 in order to allow 
    	 * the actionbox to be used, it will be switched back to 91 when the thickbox gets closed.
    	 * Set the 4th Param to true in order to unfix the Thickbox, so it scrolls away on scolling the page
    	 * 
    	 * param allowActionbox is deprecated caus all Actionboxes are in front of the overlay but behind the actionbox now
    	 *  
    	 * @param string element
    	 * @param string elementsTitle
    	 * @parem boolean allowActionbox DEPRECATED
    	 * @parem boolean allowScroll
    	 */
    	openThickbox: function ( elementName , elementsTitle , allowActionbox , allowScroll ) {
    		allowActionbox = true;
    		allowScroll = allowScroll !== undefined ? allowScroll : false;
    		if( this.currentThickbox !== null ) {
    			this.closeThickbox(
    						$('#content_thickbox_'+this.currentThickbox[0]),
    						$('#content_thickbox_'+this.currentThickbox[0]).parent().parent(),
    						this.currentThickbox[2],this.currentThickbox[3]);
    		}

    		this.currentThickbox = new Array( elementName , elementsTitle , allowActionbox , allowScroll );

    		var tbContent = $('#content_thickbox_'+elementName);
    		var thickbox = tbContent.parent().parent(); 
    		var headline = thickbox.find( 'h2' );
    		// console.log(tbContent );
    		var TB_WIDTH = thickbox.width();
    		var TB_HEIGHT = thickbox.height();
    		
    		$(".close_thickbox").bind( 'click' , function() { 
    			Common.Thickbox.closeThickbox( thickbox , tbContent , allowActionbox , allowScroll );
    			return false;
    		});
    		var pagesize = Common.getViewportDimensions();
    		var page_x = pagesize.width;
    		var page_y = pagesize.height;	
    		if (typeof document.body.style.maxHeight == "undefined") {	//if IE 6
    			$(window).bind( 'resize' , function(){Common.Thickbox.refreshOverlay();} );
    			$(window).bind( 'scroll' , function(){Common.Thickbox.refreshOverlay();} );
    				$("body","html").css({height: "100%", width: "100%"});
    				$("body","html").css("overflow","hidden");
    		}
    		$('#TB_overlay_messageLayer').bgiframe().show();
    		
    		if( allowScroll ) {
    			// Bei Allow Scroll miuessen wir zum Top springen
    			window.scrollTo( 0 , 0 );
    			$( '.TB_layer_container' ).css( 'position' , 'absolute' );
    		}

    		
    		// thickbox.bgiframe();
    		thickbox.show();
    		tbContent.show();
    		Common.Thickbox.refreshOverlay();
    		if( null !== elementsTitle) {
    			headline.html( elementsTitle );
    		}
    	    return false;
    	},
    	
		refreshOverlay: function() {
    		if (typeof document.body.style.maxHeight == "undefined") {	//if IE 6
    			$('#TB_overlay_messageLayer').css( {'top': document.documentElement.scrollTop });
    		}
			var pagesize = Common.getViewportDimensions();
    		var page_x = pagesize.width;
    		var page_y = pagesize.height;	
			$('#TB_overlay_messageLayer').height(page_y).width(page_x+'px');
		},

    	/**
    	 * closes thickbox by given name as it is opened
    	 * @param string tbElement
    	 * @param string tbContentElement
    	 * @param boolean allowActionbox
    	 * @param boolean allowScroll
    	 */
    	closeThickbox: function( tbElement , tbContentElement , allowActionbox , allowScroll ) {
			allowActionbox = true;
			this.currentThickbox = null;
			tbElement.find( 'h2' ).html( '' );
    		if( allowScroll ) {
    			$( '.TB_layer_container' ).css( 'position' , 'fixed' );
    		}
    		$("#TB_overlay_messageLayer").hide();
    		tbElement.hide();
    		tbContentElement.hide();
    		if (tbContentElement.selector == '#content_thickbox_mystyle') {
    			$('#content_thickbox_mystyle').attr('src',shop.baseUrl+'account/recommend');
    			$('#content_thickbox_mystyle').attr('href',shop.baseUrl+'account/recommend');
    		}
    		if (typeof document.body.style.maxHeight == "undefined") {	//if IE 6
    			$("body","html").css({height: "auto", width: "auto"});
    			$("html").css("overflow","");
    			$(window).unbind( 'resize' , function(){Common.Thickbox.refreshOverlay();} );
    			$(window).unbind( 'scroll' , function(){Common.Thickbox.refreshOverlay();} );
    		}
    		return false;
    	}
    } // end Thickbox
    
}; // end Common



/**
 * AtHome JS Library.
 */
var AtHome = {

	/**
     * Functions for search Site; Filter-Stuff; Paging-Stuff
     */
    Filter: {
      TEXT_LINK_MORE : 'mehr',
      TEXT_LINK_LESS : 'weniger',
      
      
      init_searchresult_product_S_mouseOver: function()
        {
            $('#content_col #search #search_results .product_single_s, .special_product_view .product_single_s')
            .hover(
            function(){
             $(this).children('.product_content')
             .bgiframe()
             .animate(
            	{height: 145}, 500) 
             .css('z-index','40') ;
             
             
            },
            function(){
                $(this).children('.product_content')
                .css('z-index', 20)
                .animate(
                {height: 0}, 700);   
            }
            );  
        }, // end init_searchresult_product_S_mouseOver
        
        
        // bei Resize zwischen relevanten Werten browser_width setzen
        change_sizes: function(browser_width){
        
            if (browser_width >= 1000 && browser_width <= 1480) {
                $('#browser_width').attr('value', browser_width);
            }
            
            
            
            // 1. Stufe: Änderungen bei klein
            if (browser_width < 1125) {
                if ($('#search .product_single_s').size() > 0) {
                
                    $('#wrapper').width('943px');
                    $('#content_col').width('707px');
                    $("#search_results .product_single_s").removeClass('last');
                    $("#search_results .product_single_s:eq(4)").addClass('last');
                    $("#search_results .product_single_s:eq(9)").addClass('last');
                    $("#search_results .product_single_s:eq(14)").addClass('last');
                    $("#search_results .product_single_s:eq(19)").addClass('last');
                    $("#search_results .product_single_s:eq(24)").addClass('last');
                    $("#search_results .product_single_s:eq(29)").addClass('last');
                    
                    $('#content_left').width('403px');
                    $("#content_left .product_single_s").removeClass('last');
                    $("#content_left .product_single_s:eq(2)").addClass('last');
                    $("#content_left .product_single_s:eq(5)").addClass('last');
                    
                    
                    AtHome.Actionbox.NUM_MAX_ACTIONBOX_ITEMS = 5;
                    $('#actionbox').width('727px');
                    $('#actionbox #action_content').width('705px');
                    $('#actionbox .product_line').width('295px');
                    
                    
                    
                }
            }
            
            
            // 2. Stufe: Änderungen bei klein
            if (browser_width >= 1125 && browser_width <= 1285) {
                if ($('#search .product_single_s').size() > 0) {
                
                    $('#wrapper').width('1091px');
                    $('#content_col').width('855px');
                    
                    $("#search_results .product_single_s").removeClass('last');
                    $("#search_results .product_single_s:eq(5)").addClass('last');
                    $("#search_results .product_single_s:eq(11)").addClass('last');
                    $("#search_results .product_single_s:eq(17)").addClass('last');
                    $("#search_results .product_single_s:eq(23)").addClass('last');
                    $("#search_results .product_single_s:eq(29)").addClass('last');
                    
                    $('#content_left').width('551px');
                    $("#content_left .product_single_s").removeClass('last');
                    $("#content_left .product_single_s:eq(3)").addClass('last');
                    $("#content_left .product_single_s:eq(7)").addClass('last');
                    
                    AtHome.Actionbox.NUM_MAX_ACTIONBOX_ITEMS = 8;
                    $('#actionbox').width('875px');
                    $('#actionbox #action_content').width('853px');
                    $('#actionbox .product_line').width('472px');
                    
                    
                }
            }
            // 3. Stufe: Änderungen bei klein
            if (browser_width >= 1286 && browser_width < 1439) {
                if ($('#search .product_single_s').size() > 0) {
                
                    $('#wrapper').width('1239px');
                    $('#content_col').width('1003px');
                    $("#search_results .product_single_s").removeClass('last');
                    $("#search_results .product_single_s:eq(6)").addClass('last');
                    $("#search_results .product_single_s:eq(13)").addClass('last');
                    $("#search_results .product_single_s:eq(20)").addClass('last');
                    $("#search_results .product_single_s:eq(27)").addClass('last');
                    
                    $('#content_left').width('699px');
                    $("#content_left .product_single_s").removeClass('last');
                    $("#content_left .product_single_s:eq(4)").addClass('last');
                    $("#content_left .product_single_s:eq(9)").addClass('last');
                    
                    AtHome.Actionbox.NUM_MAX_ACTIONBOX_ITEMS = 10;
                    $('#actionbox').width('1023px');
                    $('#actionbox #action_content').width('1001px');
                    $('#actionbox .product_line').width('589px');
                    
                }
            }
            // 4. Stufe: Änderungen bei klein
            if (browser_width >= 1439) {
                if ($('#search .product_single_s').size() > 0) {
                
                    $('#wrapper').width('1387px');
                    $('#content_col').width('1151px');
                    $("#search_results .product_single_s").removeClass('last');
                    $("#search_results .product_single_s:eq(7)").addClass('last');
                    $("#search_results .product_single_s:eq(15)").addClass('last');
                    $("#search_results .product_single_s:eq(23)").addClass('last');
                    $("#search_results .product_single_s:eq(31)").addClass('last');
                    
                    $('#content_left').width('747px');
                    $("#content_left .product_single_s").removeClass('last');
                    $("#content_left .product_single_s:eq(5)").addClass('last');
                    $("#content_left .product_single_s:eq(11)").addClass('last');
                    
                    AtHome.Actionbox.NUM_MAX_ACTIONBOX_ITEMS = 13;
                    $('#actionbox').width('1171px');
                    $('#actionbox #action_content').width('1149px');
                    $('#actionbox .product_line').width('767px');
                    
                }
            }
            
            // 1. Stufe bei Mittel
            if (browser_width < 1240) {
                if ($('#search .product_single_m').size() > 0) {
                    $('#wrapper').width('943px');
                    $('#content_col').width('707px');
                    $("#search_results .product_single_m").addClass('product_single_m_small_margin');
                    $("#search_results .product_single_m").removeClass('last');
                    $("#search_results .product_single_m:eq(3)").addClass('last');
                    $("#search_results .product_single_m:eq(7)").addClass('last');
                    $("#search_results .product_single_m:eq(11)").addClass('last');
                    $("#search_results .product_single_m:eq(15)").addClass('last');
                    $("#search_results .product_single_m:eq(19)").addClass('last');
                    $("#search_results .product_single_m:eq(23)").addClass('last');
                    $("#search_results .product_single_m:eq(27)").addClass('last');
                    
                    
                    $('#content_left').width('403px');
                    $("#content_left .product_single_s").removeClass('last');
                    $("#content_left .product_single_s:eq(2)").addClass('last');
                    $("#content_left .product_single_s:eq(5)").addClass('last');
                    
                    AtHome.Actionbox.NUM_MAX_ACTIONBOX_ITEMS = 5;
                    $('#actionbox').width('727px');
                    $('#actionbox #action_content').width('705px');
                    $('#actionbox .product_line').width('295px');
                }
            }
            
            // 2. Stufe bei Mittel
            if (browser_width >= 1240) {
                if ($('#search .product_single_m').size() > 0) {
                    $('#wrapper').width('1190px');
                    $('#content_col').width('954px');
                    $("#search_results .product_single_m").removeClass('product_single_m_small_margin');
                    $("#search_results .product_single_m").removeClass('last');
                    $("#search_results .product_single_m:eq(4)").addClass('last');
                    $("#search_results .product_single_m:eq(9)").addClass('last');
                    $("#search_results .product_single_m:eq(14)").addClass('last');
                    $("#search_results .product_single_m:eq(19)").addClass('last');
                    $("#search_results .product_single_m:eq(24)").addClass('last');
                    $("#search_results .product_single_m:eq(29)").addClass('last');
                    $("#search_results .product_single_m:eq(34)").addClass('last');
                    
                    $('#content_left').width('650px');
                    $("#content_left .product_single_s").removeClass('last');
                    $("#content_left .product_single_s:eq(3)").addClass('last');
                    $("#content_left .product_single_s:eq(6)").addClass('last');
                    
                    
                    AtHome.Actionbox.NUM_MAX_ACTIONBOX_ITEMS = 9;
                    $('#actionbox').width('974px');
                    $('#actionbox #action_content').width('952px');
                    $('#actionbox .product_line').width('530px');
                }
            }
            
            // 1. Stufe bei großer Ansicht 
            if (browser_width <= 1353) {
            
                if ($('#search .product_single_l').size() > 0) {
                    $('#wrapper').width('943px');
                    $('#content_col').width('707px');
                    $("#search_results .product_single_l").removeClass('product_single_l_large_margin');
                    $("#search_results .product_single_l").removeClass('last');
                    $("#search_results .product_single_l:eq(1)").addClass('last');
                    $("#search_results .product_single_l:eq(3)").addClass('last');
                    $("#search_results .product_single_l:eq(5)").addClass('last');
                    
                    $('#content_left').width('403px');
                    $("#content_left .product_single_s").removeClass('last');
                    $("#content_left .product_single_s:eq(2)").addClass('last');
                    $("#content_left .product_single_s:eq(5)").addClass('last');
                    
                    
                    AtHome.Actionbox.NUM_MAX_ACTIONBOX_ITEMS = 5;
                    $('#actionbox').width('727px');
                    $('#actionbox #action_content').width('705px');
                    $('#actionbox .product_line').width('295px');
                }
            }
            
            
            // 2. Stufe bei großer Ansicht 
            if (browser_width > 1353) {
            
                if ($('#search .product_single_l').size() > 0) {
                    $('#wrapper').width('1314px');
                    $('#content_col').width('1078px');
                    $("#search_results .product_single_l").addClass('product_single_l_large_margin');
                    $("#search_results .product_single_l").removeClass('last');
                    $("#search_results .product_single_l:eq(2)").addClass('last');
                    $("#search_results .product_single_l:eq(5)").addClass('last');
                    $("#search_results .product_single_l:eq(8)").addClass('last');
                    
                    
                    $('#content_left').width('774px');
                    $("#content_left .product_single_s").removeClass('last');
                    $("#content_left .product_single_s:eq(4)").addClass('last');
                    $("#content_left .product_single_s:eq(9)").addClass('last');
                    
                    AtHome.Actionbox.NUM_MAX_ACTIONBOX_ITEMS = 11;
                    $('#actionbox').width('1098px');
                    $('#actionbox #action_content').width('1076px');
                    $('#actionbox .product_line').width('649px');
                    
                }
            }
            
            
            $('.more_ab_products').css('left', $('#actionbox .product_line').width()+187+'px');    
            
            
            $('.action_type').each(function(){
            
                  var counter = $(this).children('.product_line').children('a').size();
                   if (counter > AtHome.Actionbox.NUM_MAX_ACTIONBOX_ITEMS)
                   {
                       $(this).children('.more_ab_products').show();  
                       
                   }
                   else
                   {
                      $(this).children('.more_ab_products').hide(); 
                   }
            });
             
            
        }, //change_sizes 
            
        // BEi Suchseiten: Resize und anpassen der Spalten-Breiten.
        init_resize_browser: function()
        {
           // on load
           var browser_width=  new Common.getViewportDimensions().width ;
           AtHome.Filter.change_sizes(browser_width);
           AtHome.Filter.init_send_browser_size(browser_width);
           
           // on resize AFTER load
           $(window).resize(function(){
               var browser_width= Common.getViewportDimensions().width ;
               AtHome.Filter.change_sizes(browser_width);
               AtHome.Filter.init_send_browser_size(browser_width);
            }); 
        }, // end Resize 

        // Pager Init
       init_pager: function(){
            
            $('.sort_by').click(function(){
                if ($(this).hasClass('active')) {
                    $('.sort_by_option').hide();
                    $(this).removeClass('active');
                }
                else {
                    
                    AtHome.Filter.resetPosition($(this), '.sort_by_option', 26);
        			$(this).addClass('active');
                    $('.set_page_num').hide();
                    $('.page_num').removeClass('active');
                }
                return false;
            });
            
            $('.page_num').click(function(){
                if ($(this).hasClass('active')) {
                    $('.set_page_num').hide();
                    $(this).removeClass('active');
                    $('#page_num_value').blur();
                }else{
                	AtHome.Filter.resetPosition($(this), '.set_page_num',21);
                    $(this).addClass('active');
                    $('.sort_by_option').hide();
                    $('.sort_by').removeClass('active');
                    $('#page_num_value').focus();
                }
                return false;
            });
            
            $('#page_num_value').keydown(function(event){
        		 if(event.keyCode==13){ 
                      
                      $('.page_num span').text($('#page_num_value').attr('value'));
                      $('.set_page_num').hide();
                      $('.page_num').removeClass('active');
                      var size = $('#product_size').attr('value');
                      // Produkte werden bei Seitenreload geladen
                      return true;
                  }
            	});
            
            
            
            $('.sort_by_option a').click(function(){
                $('.sort_by_option').hide();
                $('.sort_by').removeClass('active').text($(this).text());
                 var size = $('#product_size').attr('value');
                 // Produkte werden bei Seitenreload geladen
                 return true;
            }
            );
        }, // end init_pager
        
        resetPosition:function(item,layer, top)
            {
				// requires jquery.dimension plugin
				var offset = item.offset();
                try {
				layer.bgiframe();
			    } catch(e) { }
                if($.browser.msie && $.browser.version < 7)
                  {
                    if (layer == '.sort_by_option') {
                        $(layer).css({ top: offset.top + top + 3 + 'px',left: (offset.left +2) + 'px'});
                    }
                    else {
                        $(layer).css({ top: offset.top + top + 3 + 'px',left: (offset.left - 9) + 'px'});
                    }
                }
                else
                if($.browser.msie && $.browser.version >= 7)
                  {
                    if (layer == '.sort_by_option') {
                        $(layer).css({ top: offset.top + top + 1 + 'px',left: (offset.left +1) + 'px'});
                    }
                    else {
                        $(layer).css({top: offset.top + top +1 + 'px', left: (offset.left - 7) + 'px'});
                    }
                }
                else
                {
                    if (layer == '.sort_by_option') {
                        $(layer).css({top: offset.top + top  + 'px',left: (offset.left +1) + 'px' });
                    }
                    else {
                        $(layer).css({top: offset.top + top + 'px', left: (offset.left - 7) + 'px' });
                    }      
                }
                $(layer).show();
		},
        
        // Loading Products via AJAX/ JSON
        load_Search_Products:function (size)
        {
            // LOAD DUMMY PRODUCTS !!! Needs to be changed for real life
            
            var the_width = new Common.getViewportDimensions().width;
            var randomnumber=Math.floor(Math.random()*11);
            if (size == 's') {
                $("#search").load("../../templates/search/small_view.php?"+randomnumber+"&currentSubNav=Betten&currentNav=Schlafen&view="+size+"&browser_width="+the_width, function(){
                  AtHome.Filter.change_sizes(Common.getViewportDimensions().width); 
                  // added by Dag, Ajax Callback needs to reinit the animation handlers, the Actionboy Icos Handlers....
                  // probably todo, reinit other handlers?
                  AtHome.Filter.init_searchresult_product_S_mouseOver();
                });
            }
            else 
                if (size == 'm') {
                    $("#search").load("../../templates/search/medium_view.php?"+randomnumber+"&currentSubNav=Betten&currentNav=Schlafen&view="+size+"&browser_width="+the_width, function(){
                    AtHome.Filter.change_sizes(Common.getViewportDimensions().width);
                });
                }
                else {
                    $("#search").load("../../templates/search/large_view.php?"+randomnumber+"&currentSubNav=Betten&currentNav=Schlafen&view="+size+"&browser_width="+the_width, function(){
                    AtHome.Filter.change_sizes(Common.getViewportDimensions().width);
                    AtHome.Actionbox.initProductActions();
                });
                }  
        },    // end load_Search_Products
        
        // Adding Browser_size to Links in filter an Pager
        init_send_browser_size:function (browser_width)
        {
            $('#main_nav li a').each(function(){
            	var browser_link = $(this).attr('href');
                if (browser_link.indexOf('?')=='-1')
                {
                    if (browser_link == '#') {  // check filter-links with href="#"
                        var better_browser_link = browser_link[0] + '&browser_width=' + browser_width ;
                    }
                    else {   //with just a normal href like /cat/polstermoebel/ 
                        better_browser_link = browser_link + '?browser_width=' + browser_width;
                    }
                }
                else{ // links that have a '?' in href, like ="polster/?filter"
                    browser_link = browser_link.split('&browser_width');
                    var better_browser_link = browser_link[0]+'&browser_width='+browser_width;
                }
                $(this).attr('href', better_browser_link);
            });
            $('#special_nav_01 a').each(function(){
            	var browser_link = $(this).attr('href');
                if (browser_link.indexOf('?')=='-1')
                {
                    if (browser_link == '#') {  // check filter-links with href="#"
                        var better_browser_link = browser_link[0] + '&browser_width=' + browser_width ;
                    }
                    else {   //with just a normal href like /cat/polstermoebel/ 
                        better_browser_link = browser_link + '?browser_width=' + browser_width;
                    }
                }
                else{ // links that have a '?' in href, like ="polster/?filter"
                    browser_link = browser_link.split('&browser_width');
                    var better_browser_link = browser_link[0]+'&browser_width='+browser_width;
                }
                $(this).attr('href', better_browser_link);
            });
            $('#special_nav_02 a').each(function(){
            	var browser_link = $(this).attr('href');
                if (browser_link.indexOf('?')=='-1')
                {
                    if (browser_link == '#') {  // check filter-links with href="#"
                        var better_browser_link = browser_link[0] + '&browser_width=' + browser_width ;
                    }
                    else {   //with just a normal href like /cat/polstermoebel/ 
                        better_browser_link = browser_link + '?browser_width=' + browser_width;
                    }
                }
                else{ // links that have a '?' in href, like ="polster/?filter"
                    browser_link = browser_link.split('&browser_width');
                    var better_browser_link = browser_link[0]+'&browser_width='+browser_width;
                }
                $(this).attr('href', better_browser_link);
            });
             /*$('.view_page a').each(function(){
                var browser_link = window.location.href.split('&browser_width');
                var better_browser_link = browser_link[0]+'&browser_width='+browser_width;
                $(this).attr('href', better_browser_link);
            }
            );  */
        },    // end init_send_browser_size
        
        
//        init_search: function(){
//            jQuery(function() {
//                jQuery("#search_field").suggest(shop.baseUrl+"search/suggest",{
//                onSelect: function() {/*alert("You selected: " + this.value)*/}});
//                });
//        }, // end init_search
        
        // All Filter Stuff
        
        // This approach encodes information in the DOM / There's no MVC used. Refactor it!
        
        
        FilterControl: function (filterRootNode,size)  
        {
        	var myself=this;
        	this.size=size;
        	/* Classes for Root Node representing  the filters state */
        	this.collapsedClass="collapsed";
        	this.notCollapsedClass="not_collapsed";
        	this.extendedClass="extended";
        	this.hasSelectionClass="has_selection";
        	this.notHasSelectionClass="not_has_selection";
        	
        	/* Class for indicationg a selected Node  */
        	this.isSelectedClass="selected_item";
        	
        	/* Class representing Buttons  */
        	this.collapseButtonClass="collapse_button";
        	this.extendButtonClass="extend_button";
        	this.unselectButtonClass="unselect_button";
        	
        	
        	/* Class representing a selectable items  */
        	this.selectableClass="selectable_item";
        	
        	this.selectedNode=null;
        	this.filterRootNode=$(filterRootNode);
        	this.delayUpdates=false; /* Set to true if yo do not want instant Ajax-Requests i.e. fopr multiple calls */
        	
        	this.log = function(msg) {
        		//console.log(msg);
        	};
        	
        	this.toggleCollapse = function () {
        		myself.filterRootNode.toggleClass(myself.collapsedClass);
        		if (!myself.filterRootNode.hasClass(myself.collapsedClass)) {
        			myself.filterRootNode.addClass(myself.notCollapsedClass);
        			$(this).attr('title',"schlie\u00DFen");
        		} else {
        			myself.filterRootNode.removeClass(myself.notCollapsedClass);
        			$(this).attr('title',"\u00F6ffnen");
        		}
        		return false;
        	};
        	this.toggleExtended = function () {
        		myself.filterRootNode.toggleClass(myself.extendedClass);
        		return false;
        	};
        	this.selectNode = function (node) {
        		if (myself.selectedNode!=null)
        			myself.selectedNode.removeClass(myself.isSelectedClass);
        		myself.selectedNode=$(node);
        		myself.selectedNode.addClass(myself.isSelectedClass);
        		myself.filterRootNode.addClass(myself.hasSelectionClass);
        		myself.filterRootNode.removeClass(myself.notHasSelectionClass);
        		myself.toggleCollapse();
        		if (!myself.delayUpdates)
        			AtHome.Filter.load_Search_Products(myself.size);
        	};
        	this.unselectAllNodes = function () {
        		myself.log("unselectAllNodes...");
        		if (myself.selectedNode!=null) {
        			myself.selectedNode.removeClass(myself.isSelectedClass);
        		}
        		myself.selectedNode=null;
        		myself.filterRootNode.removeClass(myself.hasSelectionClass);
        		myself.filterRootNode.addClass(myself.notHasSelectionClass);
        		if (!myself.delayUpdates)
        			AtHome.Filter.load_Search_Products(myself.size);
        		myself.log("done unselectAllNodes!");
        	};
        	this.reset = function () {
        		myself.unselectAllNodes();
        		if (myself.filterRootNode.hasClass(myself.collapsedClass)) 
        			myself.toggleCollapse();
        		if (myself.filterRootNode.hasClass(myself.extendedClass))
        			myself.toggleExtended();
        		
        	};
        	
        	this.setUp = function () {
        		this.log("setting up FilterControl...");
        		this.filterRootNode.find("."+this.collapseButtonClass).click(this.toggleCollapse);
        		this.filterRootNode.find("."+this.extendButtonClass).click(this.toggleExtended);
        		this.filterRootNode.find("."+this.selectableClass).click(function () {myself.selectNode(this);});
        		this.filterRootNode.find("."+this.unselectButtonClass).click(this.unselectAllNodes); 
        		this.log("done setting up FilterControl!");
            };
        	
        	
        
            this.setUp();
        },
        
        
        
        filterControls: [],
        init_filter:function()
        {
        		var size = $('#product_size').attr('value'); //  This is dirty
        		$(".single_filter").each(function (index){
                	AtHome.Filter.filterControls.push(new AtHome.Filter.FilterControl(this,size));
                });
                var sliderOuterControl=AtHome.Filter.filterControls[AtHome.Filter.filterControls.length-1];

                $("#slider-range").slider({
            		range: true,
            		min: parseInt($("#smallest_price").val()),
            		max: parseInt($("#biggest_price").val()),
            		values: [parseInt($("#min_price").val()), parseInt($("#max_price").val())],
            		slide: function(event, ui) {
            			$("#min_price").val(ui.values[0]);
                        $("#max_price").val(ui.values[1]);
                        shopAction.updatePriceSelectionCount();
                	},
                	change: function(event, ui) {
                	$("ul.selected_price li").html('<a href="#" class="selectable_item">'+ui.values[0]+"&euro; bis "+ui.values[1]+"&euro; <span>(101)</span></a>");
                }
                
                
            		
            	});
            	$("#min_price").val($("#slider-range").slider("values", 0));
                $("#max_price").val($("#slider-range").slider("values", 1));
                
                $('.ui-slider-handle:first').addClass('first_slider');
                $('.ui-slider-handle:last').addClass('last_slider');
                $('#confirm_price').click(function () { 
                	if ($("#slider-range").slider('values',0)>$("#slider-range").slider('option','min')||$("#slider-range").slider('values',1)<$("#slider-range").slider('option','max'))
                	 	sliderOuterControl.selectNode($("ul.selected_price li").get(0));
                	else
                		sliderOuterControl.toggleCollapse();
                });
                
                
                $('.reset_filter').click(function () {
                	for (var i=0; i<AtHome.Filter.filterControls.length; i++) {
                		AtHome.Filter.filterControls[i].delayUpdates=true;
                    	AtHome.Filter.filterControls[i].reset();
                    	AtHome.Filter.filterControls[i].delayUpdates=false;
                	}
                	AtHome.Filter.load_Search_Products($('#product_size').attr('value'));
                });
                
                
        
        }    
         
                
             
	},
	
	
    Accordions:{
        
        init_accordion:function(){
        
           var derlink = window.location.href;
             derlink =  derlink.split( '&services_anker' )[1];
             if (derlink != undefined) {
                 derlink = derlink.split('_')[1];
                 derlink = parseInt(derlink);
              }
                else
                {
                    derlink = parseInt(0);
                }
                 
             //$(".content_text_body #accordion").accordion({ 
             //active: 1,
             //header: 'h4',
             //autoHeight: false,
             //collapsible: true
             //});
             
             $(".content_text_body.help #accordion").accordion({ 
               active: false,
               header: 'h4',
               autoHeight: false,
               collapsible: true
             });
             
             $(".content_text_body.show_first_element #accordion").accordion({ 
               header: 'h4',
               autoHeight: false,
               collapsible: true
             });
          
          $(".content_medium #accordion").accordion({ 
             active: 0,
             header: 'h4',
             autoHeight: false,
             collapsible: true
              });
          
          $('.tb_accordion').click(function(){
 
             var link_name = $(this).attr('name');
             link_name = link_name.split('services_anker_')[1];
             link_name = parseInt(link_name);
              
             $(".content_medium #accordion").accordion( 'activate' , link_name );
              
            
         });
               
         
          
         
         
        }
        
    },
    
    Actionbox: {
        
        ACTIONBOX_TIMEOUT :0,
        ACTIONBOX_STATUS_OPEN : false,
        
        
        // init the handlers for the actionbox
        init_actionbox: function() {
            $('#actionbox_handler').toggle( 
            function(){
         	   AtHome.Actionbox.animate_actionbox();
               
            },function(){
         	   AtHome.Actionbox.animate_actionbox();
               
            }),
            AtHome.Actionbox.initProductActions();
            
            if($('#action_4').css('display') == 'block')
            {
                $('#action_to_top, #action_to_bottom').css('display', 'none');
            }
            
            
            
            $('#wrapper').mouseover(function(){
                if (AtHome.Actionbox.ACTIONBOX_STATUS_OPEN === true ) {
                    window.clearTimeout(AtHome.Actionbox.ACTIONBOX_TIMEOUT);
                	AtHome.Actionbox.ACTIONBOX_TIMEOUT = window.setTimeout("AtHome.Actionbox.animate_actionbox();", 3000);

                }
            });
            $('#actionbox, #actionbox .inner_action, #actionbox .action_type .product_line a img, .extra_links a ').hover(function(){

            	window.clearTimeout(AtHome.Actionbox.ACTIONBOX_TIMEOUT); 
             
            });
            

            if($.browser.msie && $.browser.version == "6.0"){
        		$(window).scroll(function(){			
        			$("#actionbox")
        				.stop()
                        .hide()
        				.animate({"margin-top": ($('#wrapper').scrollTop()) + 30+  "px" }, 300, 
                            function(){
                                $("#actionbox").show();
                             }
                        );			
        		});
                }
        },
    	
        /**
         * Subinit for click handler on little Icons 
         * beside/below Product Teasers in Search Result
         */
        
        animate_actionbox: function(){
            
            if (AtHome.Actionbox.ACTIONBOX_STATUS_OPEN === true) {
                
                $('#actionbox').animate({bottom: -73}, 700, function(){
                        
                }); 
                $('#actionbox #actionbox_handler').css({'background-position': '46px -747px'});
               AtHome.Actionbox.ACTIONBOX_STATUS_OPEN = false;  
            } 
            else
            {
                 $('#actionbox').animate({bottom: 0}, 700, function(){
                   
                }); 
                 $('#actionbox #actionbox_handler').css({'background-position': '-144px -747px'});   
                  AtHome.Actionbox.ACTIONBOX_STATUS_OPEN = true;    
                 
            }
            //console.debug(AtHome.Actionbox.ACTIONBOX_STATUS_OPEN);
           
        }, // end animate_actionbox
         
        
        
        initProductActions: function() {
    	
        	//Wird in der producthandling.js vorgenommen
            //$('.notice_link').click(
     	    //      function(){
     	    //           AtHome.Actionbox.add_to_actionbox('1');
     	    //           return false;
     	    //       });
            //$('.compare_link').click(
 	        //   function(){
 	        //       AtHome.Actionbox.add_to_actionbox('2');
 	        //       return false;
            //});
            //$('.style_link').click(
 	        //   function(){
 	        //       AtHome.Actionbox.add_to_actionbox('3');
 	        //       return false;
            //});
            
            $('.actionbox_nums').click(
                function(){
                    AtHome.Actionbox.remove_from_actionbox($(this));
 	               return false;
                }
            );
            
            $('#action_to_top').click(
                    function(){
                    AtHome.Actionbox.show_actionbox('up');
 	               return false;
                }
            );
            
            $('#action_to_bottom').click(
                    function(){
                    AtHome.Actionbox.show_actionbox('down');
 	               return false;
                }
            );
            
        },
        
        
        // ID-Num of the current, shown box; changes during operation
        NUM_OF_CURR_BOX : 1,
        
        // changes visibility of actionboxes to show different actions
        show_actionbox: function(dir)
        {
            $('.action_type').hide();
            
            if (dir == 'up')
            {
                if(AtHome.Actionbox.NUM_OF_CURR_BOX == 1)
                {
                    AtHome.Actionbox.NUM_OF_CURR_BOX = 3;
                }
                else
                {
                   AtHome.Actionbox.NUM_OF_CURR_BOX--; 
                }
            }
            
            if (dir == 'down')
            {
                if(AtHome.Actionbox.NUM_OF_CURR_BOX == 3)
                {
                    AtHome.Actionbox.NUM_OF_CURR_BOX = 1;
                }
                else
                {
                   AtHome.Actionbox.NUM_OF_CURR_BOX++; 
                }
            }
            
            $('#action_' + AtHome.Actionbox.NUM_OF_CURR_BOX).show();
            
        },
        
       
       // number of items that can be inserted into the actionbox. Can be changed by browser-Resize
       NUM_MAX_ACTIONBOX_ITEMS : 5,
       
       // function to add products to the different actionboxes
       add_to_actionbox:function(type){
           
         
           
           $('#action_to_top, #action_to_bottom').css('display', 'block');
           
           $('.action_type').hide();
           $('#action_'+type).show();
           if (AtHome.Actionbox.ACTIONBOX_STATUS_OPEN === false) {
             
              AtHome.Actionbox.animate_actionbox();
           }
           
          
           
           
           NUM_OF_CURR_BOX = type;

               var counter = $('#action_'+type + ' .product_line a').size();
               if (counter < 30) {
                   counter_size = counter * 50;
                   
                   
                    if (counter >= AtHome.Actionbox.NUM_MAX_ACTIONBOX_ITEMS)
                   {
                       $('#action_'+type + ' .more_ab_products')
                       .show();
                   }
                   else
                   {
                       $('#action_'+type + ' .more_ab_products')
                       .hide();
                   }
                   
                   // Here there must be a function to get the right product to append
                //$('#action_'+type + ' .product_line').prepend('<a href="#" style="display:none"><img src="../../static/img/dummy/product_actionbox_' + counter + '.jpg"><span class="actionbox_nums"></span> </a>')
                
                $('#action_'+type + ' .product_line a:first').fadeIn(1500);
                // the counter has already the correct product count, so we must not increase it 
                $('#action_'+type + ' .actionbox_count').html('(' + counter + ')');
            };
            
            $('.actionbox_nums').click(
                function(){
                    AtHome.Actionbox.remove_from_actionbox($(this));
 	               return false;
                }
            );
            
             var weite = $('.product_line').css('width');
            weite = weite.substr(0,3);
            weite = parseInt(weite) + 187;
            
             $('.more_ab_products').css('left', weite+'px');   
           // alert($('.product_line').width());
        
  
       },
       
        remove_from_actionbox: function(item){
           
            var dad = $(item).parent();
            
            var counter = $(dad).parent().children('a').size()-1;
           
             if (counter > AtHome.Actionbox.NUM_MAX_ACTIONBOX_ITEMS)
                   {
                       $(dad).parent().parent().children('.more_ab_products')
                       .show();
                   }
                   else
                   {
                      $(dad).parent().parent().children('.more_ab_products')
                       .hide();
                   }
            
            
            $(dad).parent().parent().children('a').children('.actionbox_count').html('(' + counter + ')');
            $(dad).remove();
            
            
            
            
            
            
             // Here there must be a function to delete the right product
        }
       
    }, // end Actionbox
    
    
    MySpace: {
        
        init_my_compare: function(){
            
            // delete single item from compare list
            $('.one_delete').click(function(){
                
                $(this).parent().parent().children('.my_styles .compare_extra_links').css('display', 'none');
                
                if ($('#content_col .wide_product_view').size() >=1)
                {
                     $(this).parent().parent().parent().parent()
                        .animate ({
                        height: 0
                        }, 300, function(){
                            $(this).remove();
                        }
                        );
                }
                else {
                     $(this).parent().parent().parent()
                        .animate ({
                        width: 0,
                        'margin-right': 0
                        }, 300, function(){
                            $(this).remove();
                        }
                        );
                }
               
    	        // Dies geschieht �ber selbst konfigurierte JS
                //if ($('#my_styles_headline_num').size() >=1)
                //{
                //    var num = $('.special_product_view').children('.product_single_s').size()-1;
                    
                //    $('#my_styles_headline_num').html(num+' Artikel');
                //}
                return false;
            });
            
            $('#logged_out_notice_close').click(function(){
                $(this).parent().hide(400);
                
            });
            
            // delete all items from an definded area, given by the btn's attr. 'name'
            $('.all_delete').click(function(){
                
                var the_name = $(this).attr('rel');
                 
                 $(the_name).children()
                    .animate ({
                    height: 0,
                    'margin-right': 0
                    }, 300, function(){
                        $(this).remove();
                    }
                    );
                    $(the_name).html('<p>'+i18n.text_delete_all_products+'</p><br/><br/>');
                    $(this).hide(); 
                return false;
            });
            
            
            
            // move item in list left or right
            $('.move_compare_item_left').click(function(){
                
                AtHome.MySpace.move_item($(this), 'left');
            });
            $('.move_compare_item_right').click(function(){
                AtHome.MySpace.move_item($(this),'right');
            });  
        },// end init_my_compare
        
       
       move_item: function(elem, dir){
           var item = $(elem).parent().parent();     
           var twin = $(item).clone(true);
        
           if ($(item).is(":first-child"))
           {
               var first = true;
           } 
           
           if ($(item).is(":last-child"))
           {
              var last = true;
           }
           
           if (('left' == dir) && (item.prevAll().size() == 1)) {
    		   var left = $(twin).children('.product_content').children('.move_compare_item_left');
    		   var prev = $(item).prev().children('.product_content').children('.move_compare_item_left');
    		   left.addClass('inactive');
    		   left.removeAttr('href');
    		   prev.removeClass('inactive');
    		   prev.attr('href','#');
           } else if (('left' == dir) && (item.nextAll().size() == 0)) {
    		   var right = $(twin).children('.product_content').children('.move_compare_item_right');
    		   var prev = $(item).prev().children('.product_content').children('.move_compare_item_right');
    		   prev.addClass('inactive');
    		   prev.removeAttr('href');
    		   right.removeClass('inactive');
    		   right.attr('href','#');
           } else if (('right' == dir) && (item.prevAll().size() == 0)) {
    		   var left = $(twin).children('.product_content').children('.move_compare_item_left');
    		   var next = $(item).next().children('.product_content').children('.move_compare_item_left');
    		   next.addClass('inactive');
    		   next.removeAttr('href');
    		   left.removeClass('inactive');
    		   left.attr('href','#');
    	   } else if (('right' == dir) && (item.nextAll().size() == 1)) {
    		   var right = $(twin).children('.product_content').children('.move_compare_item_right');
    		   var next = $(item).next().children('.product_content').children('.move_compare_item_right');
    		   right.addClass('inactive');
    		   right.removeAttr('href');
    		   next.removeClass('inactive');
    		   next.attr('href','#');
    	   }
           
           if ('left' == dir)
           {
               if (first != true) {
                   $(twin).insertBefore($(item).prev());
                   $(item).remove();
               }
           }
           else
           {
               if (last != true) {
                   $(twin).insertAfter($(item).next());
                   $(item).remove();
               }
           }
           
           return false;
       } 
        
        
        
    }, // end MySpace
    
    // checkbox_style
    FastDeliveryCalculator: {
    	init: function() {
    		if( $('label.fastdelivery').size() > 0 ) {
    			$('label.fastdelivery').click(function() {
    				AtHome.FastDeliveryCalculator.updateDeliveryCharges();
    			});
    			$('.donation_info').find('span.checkbox').live( 'click' , function() {
    				AtHome.FastDeliveryCalculator.updateDeliveryCharges();
    			});
    		}
    	},
    	
    	
    	updateDeliveryCharges: function() {
			var data = $('.donation_info').find('input[type=checkbox]').serialize();
			$.post('../../templates/common/ajax/fastDeliveryCharges.php', data , function( response ) {
				$('#fastDeliveryCharges').html( response );
			});
    	}
    }, // end FastDeliveryCalculator
    
    // See http://malsup.com/jquery/form/#code-samples
    MaterialOrder: {
    	init: function() {
    		if( $('#content_thickbox_material_order').size() == 1 ) {
        		$('#materialOrderBack').click( AtHome.MaterialOrder.back );
        		$('#content_thickbox_material_order').find('.close_thickbox').click( AtHome.MaterialOrder.close );
        		$('.matterial_pattern_choice  h4 span a').click( function() { AtHome.MaterialOrder.deleteMaterial( this ); } );
        	
        		if( $( '#content_thickbox_material_order' ).size() == 1 ) {
        			var options = {target:'#content_thickbox_material_order',success: AtHome.MaterialOrder.callback};
        			$('#chooseMaterial').ajaxForm(options);
        		}
        		
    	    	$('.material_info').mouseover( function( event ) {
    	    		$( '#material_info_layer' ).show();
    	    	} );
    	    	$('.material_info').mouseout( function() {
    	    		$( '#material_info_layer' ).hide();
    	    	} );
    	    	$('.material_info').mousemove( AtHome.MaterialOrder.layerPos );
    	    	$('.material_info').click( function() {return false;} );
    		}
    	},

    	back: function() {
    		$('#content_thickbox_material_order').load('../thickbox/material_order.php', {step:'one'} , AtHome.MaterialOrder.callback );
    	},
    	
    	close: function() {
    		Common.Thickbox.closeThickbox( $('#content_thickbox_material_order').parent().parent() , $('#content_thickbox_material_order'));
    		AtHome.MaterialOrder.back();
    	},
    	
    	callback: function() {
			AtHome.MaterialOrder.init();
		},
		
		deleteMaterial: function( materialDeletionLink ) {
			$(materialDeletionLink).parent().parent().remove();
		}
    }, // end MaterialOrder
    

    InputDefaultTextFactory: {
    	go: function() {
    		var normalStyles = {'color':'#454545'};
			var defaultStyles = {'color':'#999999'};

    		if( $('#newsletter_field').size() == 1 ) {
    			var newsLetterInput = new Common.InputDefaultText( $('#newsletter_field') , 'Ihre E-Mail-Adresse' ,  defaultStyles , normalStyles );
    			newsLetterInput.init();
    		}
    		if( $('#login_field').size() == 1 ) {
    			var loginInput = new Common.InputDefaultText( $('#login_field') , 'Ihre E-Mail-Adresse' ,  defaultStyles , normalStyles );
    			loginInput.init();
    		}
    		if( $('#search_field').size() == 1 ) {
    			var searchField = new Common.InputDefaultText( $('#search_field') , 'Suchbegriff / Artikelnummer' ,  defaultStyles , normalStyles );
    			searchField.init();
    		}
    		if( $('#search_field_2').size() == 1 ) {
          var searchField = new Common.InputDefaultText( $('#search_field_2') , 'Suchbegriff / Artikelnummer' ,  defaultStyles , normalStyles );
          searchField.init();
        }
    		if( $('#name').size() == 1 ) {
          var name = new Common.InputDefaultText( $('#name') , 'Ihr Name' ,  defaultStyles , normalStyles );
          name.init();
        }
    		if( $('#review_message').size() == 1 ) {
          var review_message = new Common.InputDefaultText( $('#review_message') , 'Ihre Bewertung' ,  defaultStyles , normalStyles );
          review_message.init();
        }
            
            if( $('#lastname').size() == 1 ) {
    			var name = new Common.InputDefaultText( $('#lastname') , 'Ihr Nachname' ,  defaultStyles , normalStyles );
    			name.init();
    		}
            
            if( $('#surname').size() == 1 ) {
    			var name = new Common.InputDefaultText( $('#surname') , 'Ihr Vorname' ,  defaultStyles , normalStyles );
    			name.init();
    		}
            
    		if( $('#email').size() == 1 ) {
    			var email = new Common.InputDefaultText( $('#email') , 'Ihre E-Mail-Adresse' ,  defaultStyles , normalStyles );
    			email.init();
    		}
    		if( $('#city').size() == 1 ) {
    			var city = new Common.InputDefaultText( $('#city') , 'Ihr Wohnort' ,  defaultStyles , normalStyles );
    			city.init();
    		}
    		if( $('#headline').size() == 1 ) {
    			var headline = new Common.InputDefaultText( $('#headline') , 'Überschrift für die Bewertung' ,  defaultStyles , normalStyles );
    			headline.init();
    		}
            
              
            if( $('#sender_name_e').size() == 1 ) {
    			
                var senderName = new Common.InputDefaultText( $('#sender_name_e') , 'Ihr Name' ,  defaultStyles , normalStyles );
    			senderName.init();
    		}
            
            if( $('#sender_email_e').size() == 1 ) {
    			
                var senderEmail = new Common.InputDefaultText( $('#sender_email_e') , 'Ihre E-Mail-Adresse' ,  defaultStyles , normalStyles );
    			senderEmail.init();
    		}
            
            
            if( $('#recipient_email').size() == 1 ) {
    			var headline = new Common.InputDefaultText( $('#recipient_email') , 'E-Mail-Adresse des Empfängers' ,  defaultStyles , normalStyles );
    			headline.init();
    		}

    		if( $('#voting_email').size() == 1 ) {  			
                var headline = new Common.InputDefaultText( $('#voting_email') , 'Ihre E-Mail-Adresse' ,  defaultStyles , normalStyles );
    			headline.init();
    		}
    		
    		if( $('#password_lost_email').size() == 1 ) {  			
                var headline = new Common.InputDefaultText( $('#password_lost_email') , 'Ihre E-Mail-Adresse' ,  defaultStyles , normalStyles );
    			headline.init();
    		}
            if( $('#search_field_styles').size() == 1 ) {           
    			var headline = new Common.InputDefaultText( $('#search_field_styles') , 'Suchbegriff' ,  defaultStyles , normalStyles );
    			headline.init();
    		}

    		if( $('#birth_day').size() == 1 ) {
    			var birth_day = new Common.InputDefaultText( $('#birth_day') , 'TT' ,  defaultStyles , normalStyles );
    			birth_day.init();
    		}
    		if( $('#birth_month').size() == 1 ) {
    			var birth_month = new Common.InputDefaultText( $('#birth_month') , 'MM' ,  defaultStyles , normalStyles );
    			birth_month.init();
    		}
    		if( $('#birth_year').size() == 1 ) {
    			var birth_year = new Common.InputDefaultText( $('#birth_year') , 'JJJJ' ,  defaultStyles , normalStyles );
    			birth_year.init();
    		}
    		if( $('#reg_password').size() == 1 ) {
    			var reg_password = new Common.InputDefaultText( $('#reg_password') , '••••••••••••' ,  defaultStyles , normalStyles );
    			reg_password.init();
    		}
    		
    		if( $('#payment_method_coupon').size() == 1 ) {
    			var coupon = new Common.InputDefaultText( $('#payment_method_coupon') , i18n.couponDefault ,  defaultStyles , normalStyles );
    			coupon.init();
    		}
    	}
    },
    
    ToolTip: {
    	defaultTTOptions: {
			showTitle: false,
			arrows: false,
			waitImage: false,
			closeText: i18n.tooltipGlossaryClose,
			cluezIndex: 77, // just behind the actionbox (anf TB Overlay and TB)
			activation: 'hover',
			hoverTimeout: 700,
			positionBy: 'mouse',
			fx: {
		        open:       'fadeIn', // can be 'show' or 'slideDown' or 'fadeIn'
		        openSpeed:  ''
    		}
    	},
    	
    	initAll: function() {
    		try {
        		this.GlossaryToolTip.init();
        		this.ActionboxButtonTip.init();
    		} catch( e ) {}
    	}, // end  initAll
    	
    	GlossaryToolTip: {
    		init: function() {
				var options = $.extend({
					cluetipClass: 'yourHome-glossar',
    			    topOffset: '0',
    			    leftOffset: '0',
    			    width: '350px'

				} , AtHome.ToolTip.defaultTTOptions);
		    	$( 'a.tooltip-glossar' ).cluetip( options );    	
    		}
    	}, // end GlossaryToolTip

    	ActionboxButtonTip: {
	   		init: function() {
    			var options = $.extend({
	    				cluetipClass: 'yourHome-actionbox',
	    			    width: '98px',
	    			    topOffset: '-20px',
	    			    leftOffset: '0',
	    			    splitTitle: '|'
	    			} , AtHome.ToolTip.defaultTTOptions);
    			$( '.product_single_m .extra_links a , .product_single_l .extra_links a , .product_single_s .extra_links a' ).cluetip( options );
    			
			}
    	} // end ActionboxButtonTip
    	
    }, // end ToolTip
    
    
    Bookmarks : {
    	init : function() {
        
	        var output			= '<span>Diese Seite merken:</span>';
	        var pageUrl			= encodeURIComponent(location.href);
	        var pageTitle		= encodeURIComponent(document.title);
	        var shareObjects	=
	            {"twitter": {
                	"url":"http://twitter.com/home?status=Currently reading " + pageTitle + " (" + pageUrl + ")",
                	"title":"Twitter",
                	"options":""
            	},
            	"google": {
	                "url":"http://www.google.com/bookmarks/mark?op=add&hl=de&bkmk=" + pageUrl + "&annotation=&labels=&title=" + pageTitle,
	                "title": "Google",
	                "options":""
	                },
	            "deli": {
	                "url":"http://delicious.com/save?v=5&noui&jump=close&url=" + pageUrl + "&title=" + pageTitle,
	                "title":"deli.cio.us",
	                "options":"toolbar=no,width=550,height=550"
	            },
	            "wong": {
	                "url":"http://www.mister-wong.de/index.php?action=addurl&bm_url=" + pageUrl + "&bm_description=" + pageTitle,
	                "title":"Mr. Wong",
	                "options":""
	            },
	            "facebook": {
	                "url":"http://www.facebook.com/sharer.php?u=" + pageUrl + "&t=" + pageTitle,
	                "title":"Facebook",
	                "options":"toolbar=0,status=0,width=626,height=436"
	            }
	
	        };
	
	        for (var key in shareObjects) {
	            output = output + '<a class="' + key + '" title="' + shareObjects[key]['title'] + '" href="#" onclick="javascript:window.open(\'' + shareObjects[key]['url'] + '\', \'' + key + '\', \'' + shareObjects[key]['options'] + '\');return false;"/>';
	        }
	
	        jQuery('#social_bookmarks').html(output);
    	}
    }
}; // end AtHome

function showResponse(responseText, statusText) {
	Common.Thickbox.openThickbox('newsletter', 'Newsletter');
} 

function EMail(s)
{
	var a = false;
	var res = false;
	if(typeof(RegExp) == 'function')
	{
		var b = new RegExp('abc');
		if(b.test('abc') == true){a = true;}
	}

	if(a == true)
	{
		reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
			'(\\@)([a-zA-Z0-9\\-\\.]+)'+
        	'(\\.)([a-zA-Z]{2,4})$');
		res = (reg.test(s));
	}
	else
	{
		res = (s.search('@') >= 1 &&
			s.lastIndexOf('.') > s.search('@') &&
			s.lastIndexOf('.') >= s.length-5)
	}
	return(res);
}

// DOCUMENT READY
$(document).ready(function(){
	if($("#newsletter_form").size()>0) {
		var options = { 
				target:        '#content_thickbox_newsletter',   // target element(s) to be updated with server response 
				success:       showResponse,  // post-submit callback
				cache:		   false
		}; 	
		
		// bind form using 'ajaxForm' 
		$('#newsletter_form').ajaxForm(options);
	};
	
	if($('#newsletter_register_checkbox').size()>0){
	  $('#newsletter_register_checkbox').attr('checked',true);
  }

    if($(".search_box").size()>0)
    	$(".search_box").suggest(shop.baseUrl + 'search/suggest');
    
    if($(".no_result").size()>0)
      $(".no_result").suggest(shop.baseUrl + 'search/suggest');
    
    // Init social bookmarks
    AtHome.Bookmarks.init();
    
	// Init Thickbox opener Links
	Common.Thickbox.init();
	
	Common.Printer.init();
	
	if ($('#actionbox').size() > 0) {
	     var actionbox = new AtHome.Actionbox.init_actionbox();
	 }
	// Init all input fileds with their defaults and bahvior, see InputDefaultTextFactory
	AtHome.InputDefaultTextFactory.go();

	// Hover bei kleiner Produkt-Übersicht
	if($('#search #search_results .product_single_s').size()>0 || $('.special_product_view .product_single_s').size()>0 )  {
	     
        var init_searchresult_product_S_mouseOver = new AtHome.Filter.init_searchresult_product_S_mouseOver();
	}
	//search_field / Suggest
//	 var init_searchresult_product_S_mouseOver = new AtHome.Filter.init_search(); 
	  
    if ($('.pager').size() > 0) {
        
        AtHome.Filter.init_pager();
    } 
	// auf allen Produkt-Seiten, bei denen man resizen / filtern kann  
	 if(($('#search').size()>0) && ($('.trends').size() == 0)){
		 if($('#filter').size()>0){
			 var init_filter = new AtHome.Filter.init_filter();
		 }
	     var init_resize_browser = new AtHome.Filter.init_resize_browser(); 
	 }
	 
	 if ($('#accordion').size() > 0) {
		 AtHome.Accordions.init_accordion();
     }
   
    if ($('.my_space .scrollablecontainer').size() > 0) {
        var scroller_1 = new AtHome.Scroller('scroller_1', 4);
        scroller_1.init();
    }
    
    if (($('.my_space').size() > 0) || ($('.my_options').size() > 0)) {
        var init_compare = new AtHome.MySpace.init_my_compare();
    }  
    
    if( $('#delivery_address_switch').size() > 0 ) {
    	var deliveryAddress = new Melodeon('#delivery_address_switch' , 'div.radio_style' , 'div.delivery_address_content' , '');
    }
    
    if( $('#payment_method_switch').size() > 0 ) {
    	var paymentMethod = new Melodeon('#payment_method_switch' , 'div.radio_style' , 'div.payment_method_content' , '');
    }
    
    if( $('.packet_shop_view').size() > 0 ) {
    	var packetShops = new Melodeon('.packet_shop_view' , 'div.radio_style' , 'div.packet_shop_info' , 'bold');
    }
    
    if( $('.code_info').size() > 0 ) {
    	$('.code_info').mouseover( function() {
    		$( '#cvc_info_layer' ).show();
    	} );
    	$('.code_info').mouseout( function() {
    		$( '#cvc_info_layer' ).hide();
    	} );
    	$('.code_info').click( function() {return false;} );
    }
    
    var uAgent = navigator.userAgent.toLowerCase();

    if( uAgent.match(/firefox/) && uAgent.match(/mac/) ) {
    	// Opera/9.64 (X11; Linux x86_64; U; de) Presto/2.1.1
    	// Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; de; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3
    	$( 'button.btn_submit span , button.btn_submit_brown span , button.btn_function span , button.btn_function_brown span , button.btn_green span , button.btn_green_brown span' ).css('padding-top','1px');
    }
    if( uAgent.match(/opera/) ) {
    	$( 'button.btn_submit span , button.btn_submit_brown span , button.btn_function span , button.btn_function_brown span , button.btn_green span , button.btn_green_brown span' ).css('padding-top','2px');
    }
    
    AtHome.FastDeliveryCalculator.init();
    AtHome.MaterialOrder.init();
    AtHome.ToolTip.initAll();
});