$(function(){

	$('a[rel~=blank],a[rel~=external]').each(function(){
		$(this).attr('target','_blank');
	});

	$('.email').pMail();
	
	$.UtilAjax();
	
	$('#banner_topo').flash({
		src: DEFAULT_URL+'swf/banner.swf?1',
		width: 770,
		height: 200,
		wmode: 'transparent'
	});
	
	var _biggerlink = ['#index #conteudo div.empresa'].join(',');
	if($(_biggerlink).length > 0){
		$.addPlugin('biggerlink');
		$(_biggerlink).biggerlink();
	};

	if($('body').attr('id') == 'contato'){

		$.fn.fileUpload = function(maxSave,fileType,envio_id,show_id){
			that = this;
			fileType = (fileType || 'jpg|jpeg|gif|png');
			maxSave = (maxSave || 0);
			maxSave = (maxSave > 0) ? maxSave : -1;
			envio_id = (envio_id || 'envio_de_arquivos');
			show_id = (show_id || 'show_arquivos');
			if(maxSave != -1){
				maxSave = maxSave - $('#'+show_id+' ul li').length;
				maxSave = (maxSave < 0) ? 0 : maxSave;
			}
			function toggleInput(max){
				if(max == 0){
					$('#'+envio_id).hide();
				}else{
					$('#'+envio_id).show();
				}
			}
			toggleInput(maxSave);
			function excluirFoto(url, obj){
				$.ajax({
					async: true,
					cache: false,
					url: url,
					complete: function(){
						if($(obj).parent().parent().children('li').length < 2){
							$(obj).parent().parent().parent().remove();
						}else{
							$(obj).parent().remove();
						}
					}
				});
			}
			$('#'+show_id+' ul li a.exclude').click(function(e){
				if(confirm('Você confirma a Exclusão deste registro?')){
					excluirFoto(this.href.toString(), this);
					if(maxSave > -1){
						maxSave++;
						toggleInput(maxSave);
						that.get(0).MultiFile.max = maxSave;
					}
				}
				e.preventDefault();
				return false;
			});
			$.addPlugin('MultiFile');
			$(that).MultiFile({
				accept: fileType,
				max: maxSave
			});
			return that;
		}
	
	}
	
});
$(window).load(function(){
	if($('#index').length > 0){
		$.addPlugin('jcarousellite');
		$prod = $('#index #conteudo div.produtos');
		$prod.find('ul li a strong').normalizeHeight();
		$prod.jcarousellite({
		    visible: 5,
		    start: 0,
		    auto: 2000,
		    speed: 2000
		}).hide().addClass('produtos_show').delay(500).fadeIn('slow');
	}
});
//ie6 fixes =/
if($.browser.msie && parseInt($.browser.version) < 7){
	//image flickr
	try{document.execCommand('BackgroundImageCache', false, true)}catch(e){};
	//png
	$(window).load(function(){
		var _ifixpng = ['#topo h1 a'].join(',');
		if($(_ifixpng).length > 0){
			$.addPlugin('ifixpng','ifixpng/ifixpng2');
			$(_ifixpng).ifixpng();
		};
	});
}
