/* Shopping cart */
Cufon.replace('.rma th.cf, .rma tbody h4.cf, .rma-content label, .rma-content h3, #review-link-opener, .account-create .agreement, .rating-options, .account-login p.required, .sidebar .crosssell .qtty label, .newsletter .legend, .checkout-multishipping-address-editshipping .control p, .multiple-addresses-checkout .heading li, .addresses-list h3, .my-preferences .box-title, .form-list .input-box em, .close-link, #payment_form_ccsave label, #shipping-new-address-form label, .sidebar .shipping .sub-title, .sidebar .shipping .sp-methods dd label, .form-list label, .account-create .form-list label, .account-login .form-list span.label, .forgot-password label', {fontFamily: 'Gotham Book'});
Cufon.replace('.checkout-multishipping-overview .totals table td.gc strong, .widget-new-products .widget-title h2, .checkout-multishipping-overview .totals table td:not(".last"), .checkout-multishipping-overview .totals table th strong, .checkout-cart-index .page-title h1, .rma-content .page-title h2, .account-login .page-title h1, .forgot-password .page-title h1, .multiple-addresses-checkout .page-title h1, .account-create .page-title h1, label.qty, .cart .totals tbody td, .cart .totals tbody th', {fontFamily: 'Gotham Light'});
Cufon.replace('.widget-new-products .widget-title h2 span, .multiple-checkout .grand-total, .multiple-addresses-checkout .section-title, .event .status, .enterprise-invitation-index-index .buttons-set a span, button.button span span, .grouped-items .availability, .multiple-addresses-checkout .page-title h1 span, .checkout-cart-index .page-title h1 span, .rma-content .page-title h2 span, .account-login .page-title h1 span, .forgot-password .page-title h1 span, .account-create .page-title h1 span, .sidebar .shipping .sp-methods dt, .cart .buttons-set .button span span, .cart .totals tfoot td, .sidebar .shipping .price, #shipping-methods-container h3, h2.sub-section', {fontFamily: 'Gotham Black'});
Cufon.replace('.checkout-multishipping-shipping .col-2 .data-table tbody td.last, .review-summary-table th.label, .review-summary-table td.label, .product-review .product-name, .sidebar .crosssell h2, .sidebar .shipping h2, .cart-table thead th, .cart .price, .checkout-cart-index .product-name a, .cart-table .standart-options, .cart-table .giftcard-options dt, .checkout-switcher li', {fontFamily: 'Gotham Medium'});
Cufon.replace('.product_details .box-reviews dt, .checkout-cart-index .sidebar .button span span, .cart .deals .btn-gc span span, .cart .deals .btn-coupon span span, .shipping-cols address', {fontFamily: 'Gotham Bold'});

Cufon.replace('.messages ul li, #product_submenu li a, #content h2, h3.product_related, .my-account-page .page-title h1, .opc .step-title, ul.caption li',
				{hover: true, fontFamily: 'Gotham Light'});

Cufon.replace('.multiple-checkout .data-table thead th, .multicheckout-address > .sub-title, .multicheckout .cf-title, .event .event-dates .date-part, .product_details .review-summary-table th, #invitations-list-table thead th, .catalogsearch-result-index h3, .sp-methods > dt',
				{hover: false, fontFamily: 'Gotham Light'});
Cufon.replace('.sp-methods > dt',
				{hover: false, fontFamily: 'Gotham Light'});
Cufon.replace('#checkout-step-payment .giftcard label, .multicheckout .giftcard label, #checkout-step-payment .discount label, .multicheckout .discount label',
				{hover: false, fontFamily: 'Gotham Light'});
Cufon.replace('.sp-methods dd li .price',
				{hover: false, fontFamily: 'Gotham Black'});
Cufon.replace('#right-column-totals .order-summary-block .table-caption, #checkout-step-payment .billing-address, #checkout-step-payment h2.subtitle, .shipping-cols h3',
				{hover: false, fontFamily: 'Gotham Black'});

Cufon.replace('.multiple-checkout .grand-total .price, #payment_form_ccsave label, .giftcardaccount label, .global-header .block-list .product-name, .global-header .block-title, .top-cart .block-content table, #main_links, #additional_links, #footer_bottom .left, #product_left h4, #product_technologies h4',
				{hover: true, fontFamily: 'Gotham Medium'});

Cufon.replace('.multiple-addresses-checkout .data-table .item-options dt, .my-account-page .legend, .multiple-addresses-checkout .legend, .global-header .block-title', {hover:{ color: '#000000' }, fontFamily: 'Gotham Medium'});

Cufon.replace('.grouped-items .product-name, .product-new, #footer_content h4, #product_left h3.product_intro, #prod_desc_bttm div.sub div h3, #buy_item h3, #buy_item div, .download_tab_title',
				{hover: true, fontFamily: 'Gotham Bold'});

Cufon.replace('.multiple-addresses-checkout .info-box .box-title, .checkout-multishipping-overview .totals tr.last td strong, .my-account-page .page-title h1 span, .rollover .headline, .rollover .availability, .rollover .btn-cart, .rollover .add-to-links, #content h2.product_name, .item span.f, #content h2 strong, h3.product_related span, .buy_now, .login-form #send2 span, #instal_steps span',
				{hover: true, fontFamily: 'Gotham Black'});

Cufon.replace('.multiple-addresses-checkout .product-name, .sidebar .block-account li.current, .sidebar .block-account li a, #checkout-step-login h4', {hover: true, fontFamily: 'Gotham Black'});
Cufon.replace('.grouped-items .qtty label, #checkout-step-login h4 span', {hover: true, fontFamily: 'Gotham Light'});
Cufon.replace('.checkout-multishipping-overview .totals table td.gc strong .price, .multiple-addresses-checkout .data-table .item-options dd, .my-account-page thead th, .my-account-page thead td, .edit-account label, .info-box .box-title, .global-header .block-content .btn-remove, #checkout-step-login .col-1 .form-list label, #opc-review .data-table td', {hover: true, fontFamily: 'Gotham Book'});

Cufon.replace('.catalog-product-compare-index .btn-cart',
		{hover: true, fontFamily: 'Gotham Black'});

Cufon.replace('.rma-content p, .newsletter label, .multiple-checkout .col3-set address, .product_details .box-reviews dd p, .product-review .details p, .addresses-list address, .my-preferences label, #invitations-list-table tbody, .storecredit .account-balance p, .dashboard .welcome-msg p, .info-box .box-content, .catalog-product-compare-index th, .catalog-product-compare-index td:not(".no-cf"), #slides_container .sliderItem .desc, .smallSliderItem a, #slides_prod .sliderItem a, #prd_right_nav span.text, .login-form A,  .forgot-password A, .forgot-password p, #checkout-step-login ul, #checkout-step-login p, .account-login p, #co-shipping-form .wide h2',
				{hover: true, fontFamily: 'Univers-LT-Std-Condensed'});
Cufon.replace('#billing-address-label-msh', { fontFamily: "Univers-LT-Std-Condensed" });

Cufon.replace('#checkout-step-login .col2-set .col-2 .form-list li label, .event .event-dates .time-part, .global-header .no-items p', {fontFamily: 'Gotham Book'});
Cufon.replace('.multiple-addresses-checkout .info-box .box-title, .storecredit .account-balance .price, .account-login .fieldset h2', {fontFamily: 'Gotham Black'});

Cufon.replace('.account-create .sub-title, .account-create .button span span, .forgot-password .button span span, .global-header .actions .button span span, .catalog-product-compare-index .availability,  .catalog-product-compare-index .page-title h1', { fontFamily: 'Gotham Black'});

Cufon.replace('.h span, #product_cat',
				{hover: true, fontFamily: 'MINI 7 Condensed'});

Cufon.replace('.checkout-multishipping-success .multiple-checkout, .global-header .account-links li a, .login-form label, .forgot-password H2',
		{hover: true, fontFamily: 'Gotham Book'});

Cufon.replace('.catalog-product-compare-index .btn-cart',
		{hover: true, fontFamily: 'Gotham Black'});

Cufon.replace('.multiple-addresses-checkout .info-box address.box-content, ',
		{hover: true, fontFamily: 'Gotham Bold'});

Cufon.replace('.category-products .add-to-links a', {hover:{fontFamily: 'Gotham Black'}, fontFamily: 'Gotham Black' });
Cufon.replace('.add-to-links a', {hover:{fontFamily: 'Gotham Black'}, fontFamily: 'Gotham Light' });
Cufon.replace('.category-products .add-to-links a', {hover:{fontFamily: 'Gotham Black'}, fontFamily: 'Gotham Black' });
				
/* Region selector */
Cufon.replace('.checkout-multishipping-overview .totals table td .price, #wishlist-table th.product-name h2, .region .name', {fontFamily: 'Gotham Medium'});
Cufon.replace('.my-rewards .info-box .box-title, .my-account .table-caption, .my-account .sub-title, .region .languages li', {hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('#region_close', {fontFamily: 'Gotham Medium'});
Cufon.replace('#region_label', {fontFamily: 'Gotham Light'});
Cufon.replace('.multiple-addresses-checkout .table-caption, .account-login .button span span, h3.press-title', {fontFamily: 'Gotham Black'});


/* site search */
Cufon.replace('.checkout-multishipping-overview .col-2 .data-table td.a-right, .checkout-multishipping-overview .col-2 .data-table td.a-center, #checkout-review-table-wrapper tr td, #site_search_close A', {fontFamily: 'Gotham Medium'});
Cufon.replace('#checkout-step-shipping_method .sp-methods > dt, p.required, #site_search .text', {fontFamily: 'Gotham Book'});

//Cufon.replace('.btn-cart span', {hover:{color:'black'}, fontFamily: 'Gotham Black'});





Cufon.replace('.checkout-multishipping-overview .info-box p.box-content', {fontFamily: 'Gotham Book'});
Cufon.replace('.checkout-multishipping-overview .info-box p.box-content .price, .checkout-multishipping-overview .col2-set div.box-content table tr td:even', {fontFamily: 'Gotham Black', color:'black'});
Cufon.replace('.multiple-addresses-checkout .sidebar .block-title, #checkout-progress-state, .checkout-multishipping-overview .col2-set div.box-content table tr td:odd', {fontFamily: 'Gotham Black'});

/* separate entities for Cufon.refresh() */

Cufon.replace('#desc_bttm_navi li',
		{hover: true, fontFamily: 'Gotham Book'});
Cufon.replace('#instal_steps a.normal',
		{hover: true, fontFamily: 'Gotham Book'});

Cufon.replace('#prod_desc_bttm ul.navi a',
		{hover: true, fontFamily: 'Gotham Black'});
Cufon.replace('#opc-shipping_method .sub-title, .sp-methods dd li .price, #instal_steps a.active',
		{hover: true, fontFamily: 'Gotham Black'});

Cufon.replace('.opc-progress-container .block-content dd, .follow-us', {fontFamily: 'Gotham Medium'});
Cufon.replace('.opc-wrapper .page-title h1', {fontFamily: 'Gotham Light'});
Cufon.replace('.opc-wrapper .page-title h1 span, .opc-progress-container .block-content dt, .opc-progress-container .opc-block-progress .block-title, #multiship-addresses-table thead th.cf', {fontFamily: 'Gotham Black'});
Cufon.replace('.opc-block-progress dt.complete a.edit-link', {fontFamily: 'Univers-LT-Std-Condensed'});


Cufon.replace('.checkout-multishipping-overview .heading li', {hover: true, fontFamily: 'Gotham Light'});


Cufon.replace('#right_path', {hover: true, fontFamily: 'Univers-LT-Std-Condensed'});
Cufon.replace('#type_select a.normal', { hover: { fontFamily: 'Gotham Bold' }, fontFamily: 'Gotham Light' });
Cufon.replace('#type_select a.active', { hover: { fontFamily: 'Gotham Bold' }, fontFamily: 'Gotham Bold' });
Cufon.replace('#right_path', {hover: true, fontFamily: 'Univers-LT-Std-Condensed'});

//Added by JK
Cufon.replace('ul#tabbed_nav8 li a, ul#tabbed_nav8 li.active a, .cs_general_longer p.faqs-header',
		{hover: true, fontFamily: 'Gotham Black'});
Cufon.replace('ul#tabbed_nav7 li a, ul#tabbed_nav7 li.active a',
				{hover: true, fontFamily: 'Gotham Medium'});
Cufon.replace('.cform label, .cform label span, .cform label span span, label.cf-before, label.cf-before span, label.cf-after, label.cf-after span, ol.cf-ol li.cf-box-title, label.cf-group-after,label.cf-group-after span, span.reqtxtfld, span.reqtxtfld span',
		{hover: true, fontFamily: 'Gotham Book'});
Cufon.replace('p.warranty-header',
				{hover: true, fontFamily: 'Gotham Light'});
//End added by JK

jQuery(document).ready( function(){
	// choose passion
	jQuery('#choose_passion div, #choose_passion ul').mouseover( function(){
		jQuery('#choose_passion ul').show();
		jQuery('#choose_passion div').addClass('active');
	})
	.mouseout( function(){
		jQuery('#choose_passion ul').hide();
		jQuery('#choose_passion div').removeClass('active');
	});
	jQuery('#additional_links li.last').mouseover(function(){
		jQuery('#languages').show();
	})
	.mouseout(function() {
		jQuery('#languages').hide();
	});

	// big slider
	jQuery('.jFlowPrev, .jFlowNext').click( function(){return false;});
	jQuery('#slides').jFlow({
			slides: "#slides_container",
			width: "971px",
			height: "478px",
			container : '.sliderItem',
			item : '#jFlowSlide'
	});

	// small slider
	jQuery('#smallSliderContainer').wslide({
				width: 770,
                height: 240,
                horiz: true,
				autolink: 'smallSliderNavi div',
				duration: 300
	});

	

	// small images
	jQuery('#rightImages img').mouseover( function(){
		var desc = jQuery(this).attr('longdesc');
		jQuery(this).parent().parent().css('background', 'url(\''+desc+'\') right bottom no-repeat');
		jQuery(this).fadeTo(1, 0);
		jQuery('#smallSliderNavi').hide();
		if(jQuery.browser.msie && jQuery.browser.version == 7){
			jQuery('#small_slides, #smallSliderContainer-wrap').width(598);
			jQuery('#rightImages').width(358);
		}
		else{
			jQuery('#small_slides').width(598);
		}
		jQuery(this).width(358).height(240);
		jQuery('#rightImages img').not(jQuery(this)).hide();
	})
	.mouseout( function(){
		jQuery(this).stop();
		jQuery(this).fadeTo(1, 1, function(){
			jQuery('#smallSliderNavi').show();
			if(jQuery.browser.msie && jQuery.browser.version == 7){
				jQuery('#small_slides, #smallSliderContainer-wrap').width(770);
				jQuery('#rightImages').width(201);
			}
			else{
				jQuery('#small_slides').width(770);
			}
			jQuery('#rightImages img')
				.show()
				.width(201)
				.height(120);
			
		});
	})
	.each( function(){
		jQuery.preloadImages( jQuery(this).attr('longdesc') );
	});

	// products submenu
	var show_sub = false;
	jQuery('#product_menu, #product_submenu').mouseover( function(){
		show_sub = true;
		jQuery('#product_submenu').show();
	})
	.mouseout( function(){
		show_sub = false;
		setTimeout(function(){
			if(!show_sub){
				jQuery('#product_submenu').hide();
			}
		}, 200);
	});
    	
	var show_region = false;
	jQuery('#region_menu, #region_submenu').mouseover( function(){
		show_region = true;
		jQuery('#region_submenu').show();
	})
	.mouseout( function(){
		show_region = false;
		setTimeout(function(){
			if(!show_region){
				jQuery('#region_submenu').hide();
			}
		}, 200);
	});
	
	jQuery('#region_close').click(function() {
		show_region = false;
		jQuery('#region_submenu').hide();
	})

    //site search
    
    var show_sitesearch = false;
	jQuery('#search_menu').click( function(){
		show_sitesearch = true;
		jQuery('#site_search').show();
	});
	
	jQuery('#site_search_close A').click(function() {
		show_sitesearch = false;
			jQuery('#site_search').hide();
	})





	// related products slider
	jQuery('#product_related_list').jcarousel({
        buttonNextHTML	: null,
        buttonPrevHTML	: null,
		wrap			: "last",
		scroll			: 2,
        initCallback	: function(c){
			jQuery('#related_slider').bind('click', function(){
				c.next();
				return false;
			});
		}
	});
    
    jQuery('#product_upsell_list').jcarousel({
        buttonNextHTML	: null,
        buttonPrevHTML	: null,
		wrap			: "last",
		scroll			: 2,
        initCallback	: function(c){
			jQuery('#upsell_slider').bind('click', function(){
				c.next();
				return false;
			});
		}
	});

	if(jQuery('#product_slider li').length > 0)
	{
		// product images slider
		jQuery('#product_slider').wslide({
					width: 486,
	                height: 450,
	                horiz: true,
					autolink: 'prd_img_nav span.images',
					duration: 300
		});
	}	
	
	if(jQuery('#product_videos li').length > 0)
	{
		parseVideos();
	}
	
	// product page - bottom pages switching
	var bttm_navi = jQuery('#prod_desc_bttm ul.navi a');
	bttm_navi.click( function(){
		var current = jQuery('#prod_desc_bttm ul.navi a.active');
		var index = bttm_navi.index(jQuery(this));
		jQuery('#prod_desc_bttm .sub_item').hide().eq(index).show();
		bttm_navi.removeClass('active');
		jQuery(this).addClass('active');
		Cufon.refresh('#prod_desc_bttm ul.navi a');
		return false;
	});
	var desc_bttm_navi = jQuery('#desc_bttm_navi a');
	desc_bttm_navi.click( function(){
		var index = desc_bttm_navi.index(jQuery(this));
		jQuery('#prod_desc_bttm .sub').hide().eq(index).show();
		desc_bttm_navi.removeClass('active');
		jQuery(this).addClass('active');
		Cufon.refresh('#desc_bttm_navi li');
		return false;
	});

	// replace img src for related product image
	jQuery('#prod_big_related')
		.bind('mouseover mouseout', function(){
			var img = jQuery(this).find('img');
			var link = img.attr('longdesc');
			img.attr('longdesc', img.attr('src')).attr('src', link);
		})
		.find('img').each( function(){
			jQuery.preloadImages( jQuery(this).attr('longdesc') );
		});

	// installation steps
	var steps = jQuery('#instal_steps a');
	steps.click( function(){
		steps.removeClass('active').addClass('normal');
		jQuery(this).addClass('active').removeClass('normal');
		var index = steps.index(jQuery(this));
		jQuery('#prod_desc_bttm .sub .step').hide()
			.eq(index).show();
			
		/* for some reason .refresh() wont work here */
		Cufon.replace('#instal_steps a', {fontFamily: "Gotham Book"});
		Cufon.replace('#instal_steps a.active', {fontFamily: "Gotham Black"});
		return false;
	});

	// // buy now button
	// jQuery('.buy_now').click( function(){
	// 	jQuery('#buy_item').show();
	// });
	// jQuery('#close_buy_item').click( function(){
	// 	jQuery('#buy_item').hide();
	// });


	if(jQuery('#content').hasClass('product_details'))
	{
		Cufon.replace('#rightLinks a',
			{hover: false, fontFamily: 'Gotham Book'});		
	}
	else
	{
		Cufon.replace('#rightLinks a',
			{hover: true, fontFamily: 'Gotham Book'});		
	}

	// product list - emulate :hover for cufon fonts
	//cufonHover(jQuery('#type_select a.normal'), 'Gotham Bold');
	cufonHover(jQuery('#content.product_details #rightLinks a'), 'Gotham Bold');
	Cufon.now();


	// IE7 fix
	if(jQuery.browser.msie && jQuery.browser.version == 7){
		//jQuery('div.item.first').css({ clear : 'both', 'margin-left' : 0 });

		jQuery('div.item a span.d').hide();
		jQuery('div.item a')
			.mouseover( function(){
				jQuery(this).find('span.d').show();
			})
			.mouseout( function(){
				jQuery(this).find('span.d').hide();
			});
	}
	
	/* remove last delimiter (<span>|</span>) on each line of product list */
    var elems = jQuery('#type_select_bottom span');
	var i, o, o_prev;
	
	for(i = 0; i < elems.length; i++) {
		o = jQuery(elems[i]).offset();
		if(i > 0 && o.top > o_prev.top) {
			jQuery(elems[i-1]).hide();
			jQuery(elems[i-1]).next().css('clear', 'left');
			//jQuery(elems[i-1]).next().next().css('clear', 'left');
		}
		o_prev = o;
	}
	
	jQuery(elems[elems.length - 1]).hide();
    
        

	jQuery('#wrapper > p').remove();
});

function cufonHover(jQueryElems, fontFamilyOnHover){
	jQueryElems
	.each( function(){
		var c = jQuery(this).clone();
		c.css({display: 'none'}).addClass('active');
		jQuery(this).after(c);
		Cufon.replace(c,
			{hover: true, fontFamily: fontFamilyOnHover});
	})
	.mouseover( function(){
		var n = jQuery(this).next();
		jQuery(this).hide();
		n.show();
		n.mouseout( function(){
			jQuery(this).hide().prev().show();
		});
	});
}

function parseVideos()
{
	var container = jQuery('#prd_vid_nav .videos');
	container.html('');
	var count_vid = jQuery('#product_videos li').length;
	var count_all = jQuery('#product_slider li').length;
	var count_img = count_all - count_vid;
	
	jQuery('#prd_img_nav .images a').each(function(i){
		if(i >= count_img)
		{
			var el = jQuery(this).detach();
			el.appendTo('#prd_vid_nav .videos');
		}
	})
}

(function(jQuery) {
	var cache = [];
	// Arguments are image paths relative to the current page.
	jQuery.preloadImages = function() {
		var args_len = arguments.length;
		for (var i = args_len; i--;) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
		}
	}
})(jQuery);



Cufon.replace('#community_submenu li a, #tech_submenu li a, #team_submenu li a',
				{hover: true, fontFamily: 'Gotham Light'});


jQuery(document).ready( function(){

	// teams submenu
	var show_sub = false;
	jQuery('#team_menu, #team_submenu').mouseover( function(){
		show_sub = true;
		jQuery('#team_submenu').show();
	})
	.mouseout( function(){
		show_sub = false;
		setTimeout(function(){
			if(!show_sub){
				jQuery('#team_submenu').hide();
			}
		}, 200);
	});
	
	// tech submenu
	var show_sub = false;
	jQuery('#tech_menu, #tech_submenu').mouseover( function(){
		show_sub = true;
		jQuery('#tech_submenu').show();
	})
	.mouseout( function(){
		show_sub = false;
		setTimeout(function(){
			if(!show_sub){
				jQuery('#tech_submenu').hide();
			}
		}, 200);
	});
	
	// tech submenu
	var show_sub = false;
	jQuery('#community_menu, #community_submenu').mouseover( function(){
		show_sub = true;
		jQuery('#community_submenu').show();
	})
	.mouseout( function(){
		show_sub = false;
		setTimeout(function(){
			if(!show_sub){
				jQuery('#community_submenu').hide();
			}
		}, 200);
	});
	
	jQuery('#team_menu').mouseover(function(){
		show_sub = false;
		setTimeout(function(){
			if(!show_sub){
				jQuery('#community_submenu, #tech_submenu, #product_submenu').hide();
			}
		}, 200);
	})
	
});

inputLabelFix = function() {
	jQuery('input[type=text]').each(function(){
		if(jQuery(this).val() != '')
		jQuery(this).css('position','relative');
	});
	
	jQuery('input[type=text]').focus(function(){
		jQuery(this).css('position','relative');
	});
	jQuery('input[type=text]').blur(function(){
		if(jQuery(this).val() == '')
		jQuery(this).css('position','static');
	});
}

decorateLabels = function(){
        $$('.input-text, textarea').each(function(item){
            var labelVal = item.up(0).previous('label'),
                formID = item.up('form'),
                periodicalTimer;
            if(item.getValue().length > 0 && typeof labelVal != 'undefined'){
                labelVal.hide();
            }

            item.observe('focus', function(){
                    if(typeof labelVal != 'undefined'){
                        labelVal.hide()
                    }
                    if(formID.identify() == 'login-form' || formID.identify() == 'quick-login-form'){
                        var periodicalTimer = new PeriodicalExecuter(function(e){
                            var passwordField = formID.down('[type="password"]');
                            if(passwordField.getValue() !== ''){
                                passwordField.up(0).previous('label').hide();
                                periodicalTimer.stop();
                                periodicalTimer = {};
                            }
                        }, 0.05);
                    }
                });
            item.observe('blur', function(){
                    if(item.getValue() == '' && typeof labelVal != 'undefined'){
                        labelVal.show();
                    }
                    
                });
        });
    }
document.observe("dom:loaded", function() {

    decorateLabels();

    var ErrorMSG = $(document.body).down('.error-msg ul'),
        messagesContainers = $(document.body).down('.messages');
    if(typeof ErrorMSG != 'undefined' && ErrorMSG.childElements().size() > 1){
        ErrorMSG.setStyle({
            height: 54+'px',
            paddingTop: 15+'px'
        });
        ErrorMSG.childElements().each(function(item){
            item.setStyle({
                'float': 'left',
                'clear': 'left'
            });
        });
    }

    if(typeof messagesContainers != 'undefined'){
        messagesContainers.childElements().each(function(item){
            if(!item.hasClassName('customer')){
                item.down().insert({
                    'before': '<a href="#Close" class="messages-close-link">Close</a>'
                });
            }
            else{
                item.down().insert({
                    'before': '<a id="quick-login-back" href="' + LOGIN_URL + '" class="messages-close">Back to login ></a>'
                });
                $('quick-login-back').observe('click', function(e){
                    var quickLoginForm = $('quick-login-wrapper');
                    e.stop();
                    if($('forgot-password-wrapper').visible()){
                        $('forgot-password-wrapper').hide();
                    }
                    if(!quickLoginForm.hasClassName('expanded')){
                        $(this).up(1).hide();
                        quickLoginForm.addClassName('expanded').show();
                    }
                    else{
                        quickLoginForm.removeClassName('expanded').hide();
                    }
                });
            }
        });
        $$('.messages-close-link').each(function(item){
            item.observe('click', function(e){
                e.stop()
                item.up().hide();
            });
        });
    }
});
Event.observe(window, 'load', function(){
    setTimeout(function(){
        decorateLabels();
    }, 1000);});
