﻿/**
	Util Class
	
	@author Diego Neitzel
	@version 11:56 26/3/2010
*/
//{

var util = {
	/*
		usage: util.focusBlur('class')
		Função que no focus, tira a imagem de fundo do input, e no blur, caso esteja sem value, põe devolta.
	*/
	focusBlur: function(cl){
		$('.'+cl+'').focus(function(){
			$('.'+cl+'').addClass('noBg');
		});
		$('.'+cl+'').blur(function(){
			if ($('.'+cl+'').val() == ''){
				$('.'+cl+'').removeClass('noBg');
			}
		});
	},	
	
	/*
		usage: util.focusBlur('class')
		Função que amplia o link da photo para todo <li> do produto. Também executa uma ação no hover (aplica class para estilização).
	*/
	amplifyLinkArea: function(lstCl){
		$('.'+lstCl+' li').hover( function(){
			if ($('.'+lstCl+'').hasClass('productsHome')){
				$(this).addClass('hoverHome');
			} else if($('.'+lstCl+'').hasClass('lstFullPage')) {
				$(this).addClass('hoverFull');
			} else {
				$(this).addClass('hoverProduct');
			}
		},function (){
			if ($('.'+lstCl+'').hasClass('productsHome')){
				$(this).removeClass('hoverHome');
			} else if($('.'+lstCl+'').hasClass('lstFullPage')) {
				$(this).removeClass('hoverFull');
			} else {
				$(this).removeClass('hoverProduct');
			}
		});
		
		$('.'+lstCl+' li:not(.iecb)').click( function(){
			var url = $(this).children('p').children('a').attr('href');
			document.location.href = url;
		});
	},
	
	
	/*
		usage: util.popUpShopCart('classLink', 'idPop')
		Função para abrir o pop de carrinho no header
	*/
	popUpShopCart: function(link, pop){
		var initPopUpShopCart;
		$('#'+pop+'').hide();
		
		$('.'+link+'').hover(function(){
			initPopUpShopCart = setTimeout(function(){
				$('#'+pop+'').slideDown('fast');
			},200);
		}, function(){
			clearTimeout(initPopUpShopCart)
		})
		$('#'+pop+'').hover(function(){}, function(){
			$('#'+pop+'').slideUp('fast');
		})
	},
	
	/**
	 * @author: Bruno Moura
	 * @version: null
	 * @method: fieldFocus
	 * @classDescription: Retira o valor do campo passado como parametro.
	 */
	fieldFocus: function(thisClass){
		$(thisClass).focus(function(){ 
		if($(thisClass).val() == "Digite aqui seu e-mail"){
			$(thisClass).val("");
		}
		});
		$(thisClass).blur(function(){		
			if($(thisClass).val() == null || $(this).val() == ""){
				$(thisClass).val("Digite aqui seu e-mail");
			}
		}); 
	}
}

/**
	Init
	
	@author Diego Neitzel
	@version 12:00 26/3/2010
*/
//{

$(function(){
	/*1*/ util.focusBlur('fldBuscar');
	/*2*/ util.amplifyLinkArea('lstProducts');
	/*3*/ util.popUpShopCart('lnkShopCart', 'popUpShopCart');
	util.fieldFocus($(".fldEmailNewsletter"))
	
})

//}



/**
	Function to show more results on side menu
	@author Diego Neitzel
	@version 14:55 20/5/2010
*/
//{
$(function(){
	$('.moreResults').hide();
	
	$('.btViewAll').click(function(){
		var _moreResults = $(this).parent().children('ul.moreResults');
		
		if(_moreResults.css('display') != 'none'){
			_moreResults.slideUp('200');
			$(this).html('[+] <a href="javascript:;">Ver Todos</a>');
		} else {
			_moreResults.slideDown('200');
			$(this).html('[-] <a href="javascript:;">Ocultar</a>');
		}
	})
})
//}


/**
	Function to show more results on side menu
	@author Diego Neitzel
	@version 14:55 20/5/2010
	@usage 
*/
//{
var dhtml = {
	open: function(urlBanner, elmWidth, elmHeight, elmTop, container){
		var _container = null;
		(container == null) ? _container = 'body' : _container = container;
		
		var _center = 0;
		_center = (elmWidth / 2);
		
		$(document.createElement('div'))
			.attr('id', 'bannerDhtmlHolder')
			.css({position: 'absolute', zIndex: '99999', top: elmTop+'px', left: '50%', marginLeft: '-'+_center+'px', display: 'none'})
			.appendTo(_container);
		
		$(document.createElement('div'))
			.attr('id', 'bannerDhtml')
			.appendTo('#bannerDhtmlHolder');
			
		$("#bannerDhtml").html('<script type="text/javascript">swfobject.embedSWF("'+urlBanner+'", "bannerDhtml", "'+elmWidth+'", "'+elmHeight+'", "9.0.0", "/locales/global/swf/expressInstall.swf", {}, {wmode: "transparent"});</script>')
			
			
		this.show();
	},
	close:function(){
		$('#bannerDhtmlHolder').hide();
		setTimeout(function(){
			$('#bannerDhtmlHolder').remove();
		},250);
	},
	show:function(){
		$('#bannerDhtmlHolder').show();
		setTimeout(function(){$('#bannerDhtmlHolder').remove()},12000);
	}
}
//}


