﻿$().ready(function() {

	var init;
	function MostrarImagemProduto(obj) {
		clearTimeout(init);
		var pos = obj.offset();
		var img = obj.attr('src').replace('Miniatura/', 'Grande/');
		var nomeimg = img.split('/')[4].replace(/-/g, ' ').replace('.jpg', '');
		nomeimg = (nomeimg.indexOf('Miolo') != 0 && nomeimg.indexOf('Mapa') != 0 && nomeimg.indexOf('Refil') != 0) ? nomeimg.substring(nomeimg.indexOf(' '), nomeimg.length).substring(nomeimg.indexOf(' ')-1, nomeimg.length) : nomeimg;
		var esgotado = '';
		//alert ($(this).parent().hasClass('esgotado'))
		$('#imagemgrande').show();
		if (obj.parent().hasClass('esgotado')) {
			$('#imagemgrande').html('<h3>' + nomeimg + '</h3><img src="' + img + '" width="320" height="405" alt="Imagem" /><span></span>');
		} else {
			$('#imagemgrande').html('<h3>' + nomeimg + '</h3><img src="' + img + '" width="320" height="405" alt="Imagem" />');
		}
		$('#imagemgrande').css({ 'top': (100 + pos.top) + 'px' });
		//$('#imagemgrande').css({ 'top': (170 + pos.top) + 'px', 'left': (pos.left - 210) + 'px' });
	}

	$('.listaimagens > li > img').bind('mouseover', function() {
		$(this).parent().addClass('over');
		MostrarImagemProduto($(this));
	});
	$('.listaimagens > li > img').bind('mouseout', function() {
		$(this).parent().removeClass('over');
		init = setTimeout(function() { $('#imagemgrande').hide() }, 500);
	});

	$('.listaimagens > li.esgotado').append('<span></span>');
	$('.listaimagens > li.esgotado > span').bind('mouseover', function() {
		$(this).parent().find('img').trigger('mouseover');
	});
	$('.listaimagens > li.esgotado > span').bind('mouseout', function() {
		$(this).parent().find('img').trigger('mouseout');
	});

	$('.listaimagens > li.sobencomenda').append('<span></span>');
	$('.listaimagens > li.sobencomenda > span').bind('mouseover', function () {
		$(this).parent().find('img').trigger('mouseover');
	});
	$('.listaimagens > li.sobencomenda > span').bind('mouseout', function () {
		$(this).parent().find('img').trigger('mouseout');
	});

	$('.listaimagens > li.sobconsulta').append('<span></span>');
	$('.listaimagens > li.sobconsulta > span').bind('mouseover', function () {
		$(this).parent().find('img').trigger('mouseover');
	});
	$('.listaimagens > li.sobconsulta > span').bind('mouseout', function () {
		$(this).parent().find('img').trigger('mouseout');
	});



	//.css('border', 'solid 1px red')//;

	$('#imagemgrande').bind('mouseover', function() {
		clearTimeout(init);
		$(this).addClass('over');
	});
	$('#imagemgrande').bind('mouseout', function() {
		init = setTimeout(function() { $('#imagemgrande').hide() }, 500);
		$(this).removeClass('over');
	});


});

	// Função para abrir uma janela
	function AbreJanela(NomeJanela, URL, Largura, Altura) {
		var left = ((screen.width - Largura - 20) / 2)
		var top = ((screen.height - Altura - 35) / 2);
		var features = "width=" + Largura + ", height=" + Altura + ",status=yes,scrollbars=yes,menubar=yes,resizable=no,left=" + left + ",top=" + top + "";
		eval(window.open(URL, '', features));
		//eval(window.open(URL, NomeJanela.replace(/\s/g,''), features));
	}

	// Função para pedir confirmarção antes de abrir uma URL
	function ConfirmarAcao(msg, url) {
		var resp = confirm(msg);
		if (resp) window.location.href = url;
	}
	
	
	
	
