$(document).ready(function() {
	//iniciar Pretty photo
	$("a[rel^='prettyPhoto']").prettyPhoto({
	show_title: false,
	theme: 'light_rounded',
	allow_resize: false
	});
	$("a[rel^='prettyPhotoAtendimento']").prettyPhoto({
	show_title: false,
	opacity: 0.5,
	theme: 'dark_rounded',
	markup: '<div class="pp_pic_holder"> \
						<div class="pp_content_container"> \
							<div class="pp_left"> \
							<div class="pp_right"> \
								<div class="pp_content"> \
									<div class="pp_fade"> \
									<div id="atendimento_fechar"></div> \
										<div id="pp_full_res"></div> \
									</div> \
								</div> \
							</div> \
							</div> \
						</div> \
					</div> \
					<div class="pp_overlay atendimento"></div>',
	iframe_markup: '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>'
	});
	$("#atendimento_fechar").live("click", function(){
		$.prettyPhoto.close();			   
	})
	
	$("#Login").click(function(){
		if($('.caixa_login').css('top')=="27px"){
			$('.caixa_login').stop().animate({top: '-128px'}, 500, "easeInCubic");
		}else{
			$('.caixa_login').stop().animate({top: '27px'}, 500, "easeInCubic");	
		}		
	});
	$(".fechar_login").click(function(){
			$('.caixa_login').stop().animate({top: '-128px'}, 500, "easeInCubic");
	});

	//mouse over dos menus
	$(".menu_meio").hoverIntent(menuHover);
	
});

var LOCAL_URL = window.location.href;
LOCAL_URL = LOCAL_URL.replace("http://servidor/", "http://");

var menuHover = {    
		 sensitivity: 10,
		 interval: 50,
		 over: menuHoverOver,  
		 timeout: 300,
		 out: menuHoverOut
};


function menuHoverOver(){
	$(this).find('ul').stop().animate({top: '31px'}, 500, "easeInCubic");
};
	
function menuHoverOut(){
	$(this).find('ul').stop().animate({top: '-75px'}, 500, "easeInCubic");
};

/**
 * Verifica se o email esta no formato login@domain.com
 * @param email <string>
 * @return <bool>
 */
function validaEmail(email) {
	if(/(?:[a-zA-Z0-9\.\-\_\%\+]+)\@(?:[a-zA-Z0-9\.\-\_\%]+)\.(?:[a-zA-Z0-9]{2,4})/.test(email) == false) {
		return false;	
	}
	return true;
}

/**
 * Verifica se o numero de telefone esta no formato (xx) xxx-xxxx
 * @param telefone <string>
 * @return <bool>
 */
function validaTelefone(telefone) {
	if(/\([0-9]{2}\) [0-9]{4}\-[0-9]{4}/.test(telefone) == false) {
		return false;
	}
	return true;
}

function empty(mixed_var){
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/empty    // +   original by: Philippe Baumann
    // +      input by: Onno Marsman
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: LH
    // +   improved by: Onno Marsman    // +   improved by: Francesco
    // +   improved by: Marc Jansen
    // +   input by: Stoyan Kyosev (http://www.svest.org/)
    
    var key;    
    if (mixed_var===""||
        mixed_var===0||
        mixed_var==="0"||
        mixed_var===null||
        mixed_var===false||
        typeof mixed_var==='undefined'
    ){
        return true;
    } 
    if(typeof mixed_var=='object') {
        for(key in mixed_var) {
            return false;
        }
        return true;
    }
    return false;
}

/**
 * Gera um modal de alerta, para substituir o 'alert' normal do javascript
 * @param msg <string> Mensagem a ser mostrada
 * @param titulo <string> Titulo da janela
 * @param destroy <bool> Se a janela deve ser removida da pagina apos se clicar em 'OK' (Default: true)
 * @param callback <callback> Funcao a ser chamada quando o usuario clicar em 'OK'
 * @return
 */
function alertar(msg, titulo, destroy, callback) {
	var t;
	var kill;
	
	if(titulo != '' && titulo != null && titulo != 'undefined' && titulo != false) {
		t = titulo;
	} else {
		t = 'Alerta';
	}
	
	if(destroy === false) {
		kill = false;
	} else {
		kill = true;
	}
	
	$('<div></div>').html(msg).dialog({modal: true, 
										title: t, 
										buttons: { "OK" : function() {
																if(callback != null && callback != 'undefined') {
																	callback();
																}
																if(kill) {
																	$(this).remove();
																}
															} 
													}
										});
}
function abrirContato() {
	$.prettyPhoto.close();
	$.prettyPhoto.open('fale_conosco?iframe=true&scrolling=no&width=600&height=500')
}

$.fn.imageLoad = function(fn){
    this.load(function(){
    	fn(this);
    	return false;
    });
    return this.each( function() {
        if ( $(this).get(0).complete && $(this).get(0).naturalWidth !== 0 ) {
            $(this).trigger('load');
        }
    });
}

function Exception(error) { this.error = error; }
Exception.prototype.toString = function() { return this.error; }

var proarte = {
		e: function(s){
			var unicodeString = '';
				for (var i=0; i < s.length; i++) {
					var theUnicode = s.charCodeAt(i).toString(16).toUpperCase();
					while (theUnicode.length < 4) {
						theUnicode = '0' + theUnicode;
					}
					theUnicode = '\\u' + theUnicode;
					unicodeString += theUnicode;
			  }
			  return unicodeString;
		}
};
