var clockSound = null;
var clickSound = null;

$(document).ready(function(){
	
	fixPNG();
	
	btMenu('Home Mitsubishi Electric','/default.php','bt0','',155, '');
	btMenu('Home Aire Acondicionado','/aire-acondicionado/','bt2','',165, '');
	btMenu('Trabaja con nosotros','http://www.mitsubishielectric.es/default.htm?opc=5','bt1','',138,'_blank');
	//btMenu('About Us','default.php','bt2','',74);
	//btMenu('Contact Us','default.php','bt3','',76);
	
	/* SM2 */
	/*
	soundManager.useFlashBlock = false;
	soundManager.debugMode = false;
	soundManager.debugFlash = false;
	soundManager.flashVersion = 9;
	soundManager.url = '/aire-acondicionado/js/sm2/';
	soundManager.onload = function() {
		clickSound = soundManager.createSound({
			id: 'clickSound',
			url: '/aire-acondicionado/js/sm2/sound/lame.mp3',
			autoLoad: true,
			autoPlay: false,
			volume:100
		});
		clockSound = soundManager.createSound({
			id: 'clockSound',
			url: '/aire-acondicionado/js/sm2/sound/lamelo.mp3',
			autoLoad: true,
			autoPlay: false,
			volume:100
		});
	};
	
	$(".presta_img").click(function(){
		if(clickSound) {
			clickSound.stop();
			clickSound.play();
		}
	});
	*/
	/* SM2 End */
	
	$(".presta_img").fancybox({
		'overlayShow': true,
		'hideOnOverlayClick': true,
		'hideOnContentClick': true,
		'autoDimensions': true,
		'autoScale': true,
		'transitionIn': 'elastic',
		'transitionOut': 'elastic',
		'titlePosition': 'inside',
		'centerOnScroll': true,
		onClosed: function(){
			if(clockSound) {
				clockSound.stop();
				clockSound.play();
			}
		}
	});
	
});

function btMenu(texto, href, div, sel, width, vent)
{
	$('#'+div).flash({
		src: '/aire-acondicionado/btMenu.swf',
		width: width,
		height: 20,
		wmode: "transparent",
		scale: "noscale",
		salign: "lt",
		flashvars: {	
			texto: texto,
			selected: sel,
			ventana: vent,
			href: href
		}
	});
}

function messageAndGo(str, onclick)
{
	$.alerts.okButton = "OK";
	jAlert(str, 'Mitsubishi', onclick);
}

function message(str)
{
	$.alerts.okButton = "OK";
	jAlert(str, 'Mitsubishi');
}

function messageConfirm(str, onclick)
{
	jConfirm(str, 'Mitsubishi', onclick);
}

/*
 * Arregla los PNGs en IE6 usando los filtros de MS
 */
function fixPNG()
{
	// Solo para IE6 y posteriores
	if($.browser.msie && parseInt($.browser.version.substr(0,1)) <= 6) {
		// Todas las imagenes
		$("img").each(function(){
			var image = $(this).attr('src');
			// Que tengan un PNG
			if (image.match(/.png/i)) {
				// Le ponemos por CSS con el filter de IE la imagen y le quitamos la actual
				$(this).css({
					'backgroundImage': 'none',
					'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod='scale', src='" + image + "')"
				}).attr("src", "/aire-acondicionado/images/pix.gif");
			}
		});
		// Para todos los tags
		$("*").each(function(){
			// Que tengan un backgroundImagen: url(*.png)
			var image = $(this).css('backgroundImage');
			if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) {
				image = RegExp.$1;
				// Le cambiamos el CSS
				$(this).css({
					'backgroundImage': 'none',
					'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=" + ($(this).css('backgroundRepeat') == 'no-repeat' ? 'crop' : 'scale') + ", src='" + image + "')"
				}).each(function () {
					var position = $(this).css('position');
					if (position != 'absolute' && position != 'relative')
						$(this).css('position', 'relative');
				});
			}
		});
	}
}