
/**Bookmark**/
function bookmark() {
	appName = navigator.appName;
	appVersion = parseInt(navigator.appVersion);
	userAgent = navigator.userAgent;
	
	if ((appName == "Microsoft Internet Explorer") && (appVersion >= 4)) 
		window.external.AddFavorite('http://www.centroportugues.com','Centro Portugues');
	else {
		if (userAgent.indexOf("Firefox") != -1)
			window.sidebar.addPanel("Centro Portugues", "http://www.centroportugues.com/", "");	
		else
			alert('Para agregar TuAzar.com en tus Favoritos (Marcadores), hacer click en Favoritos (Marcadores) | Agregar Favorito (Marcador) '+'o presiona Ctrl + D (Netscape y Firefox) o Ctrl + T (Opera).');
	};
	return false;
};

function sustituir(stringToTrim) {
	return stringToTrim.replace(/] - /,"]<br /><br /><strong>");
}

/** INICIO jcarousel **/
function mycarousel_initCallback(carousel)
{
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
var mycarousel_itemList = [
    {url: 'http://static.flickr.com/66/199481236_dc98b5abb3_s.jpg', title: 'Flower1'},
    {url: 'http://static.flickr.com/75/199481072_b4a0d09597_s.jpg', title: 'Flower2'},
    {url: 'http://static.flickr.com/57/199481087_33ae73a8de_s.jpg', title: 'Flower3'},
    {url: 'http://static.flickr.com/77/199481108_4359e6b971_s.jpg', title: 'Flower4'}/*,
    {url: 'http://static.flickr.com/58/199481143_3c148d9dd3_s.jpg', title: 'Flower5'},
    {url: 'http://static.flickr.com/72/199481203_ad4cdcf109_s.jpg', title: 'Flower6'},
    {url: 'http://static.flickr.com/58/199481218_264ce20da0_s.jpg', title: 'Flower7'},
    {url: 'http://static.flickr.com/69/199481255_fdfe885f87_s.jpg', title: 'Flower8'},
    {url: 'http://static.flickr.com/60/199480111_87d4cb3e38_s.jpg', title: 'Flower9'},
    {url: 'http://static.flickr.com/70/229228324_08223b70fa_s.jpg', title: 'Flower10'}*/
];
function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, mycarousel_itemList.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};
function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    return '<img src="' + item.url + '" width="140" height="75" alt="' + item.title + '" />';
};
	/** FIN jcarousel **/
	
function random2(ini, fin)
{
	var numero = (fin - ini)*Math.random() + ini;
	return Math.round(numero);
};

function imagenesjCycle()
{
	/* Las imagenes que aparecen en el jCycle */
	var imagenes = "";	
	imagenes = imagenes + '<img src="i/iph/iph_entrada.jpg" alt="" width="681" height="265" alt="Instalaciones Centro Portugues" />';	
	//imagenes = imagenes + '<img src="i/iph/carnaval2010.jpg" alt="" width="681" height="265" alt="Carnaval 2010 Centro Portugues" />';	
	return imagenes;
};

function opcionesHeader()
{
	/* Las imagenes que aparecen en el jCycle */
	var item = "";
	var RUTAABSOLUTAITEM = "http://www.centroportugues.com/";
	item = item + '<a href="/" id="homeIcon" title="Home - Ir a la pagina Inicial del CentroPortugues.com"><img src="'+RUTAABSOLUTAITEM+'i/iconos/iconHome.png" alt="Home - Ir a la pagina Inicial" class="rollover" /></a><a href="#" id="favoritoIcon" title="Agregar CentroPortugues.com a los favoritos"><img src="'+RUTAABSOLUTAITEM+'i/iconos/iconFavorito.png" alt="Agregar a Favoritos" class="rollover bordeIMG" /></a><a href="'+RUTAABSOLUTAITEM+'recomendarweb.php" class="popup" id="recomendarIcon" title="Recomendar CentroPortugues.com a un amigo"><img src="'+RUTAABSOLUTAITEM+'i/iconos/iconRecomendar.png" alt="Recomendar a un Amigo" class="rollover" /></a><a href="'+RUTAABSOLUTAITEM+'contacto.php" id="contactoIcon" title="Informacion de contacto del Centro Portugues"><img src="'+RUTAABSOLUTAITEM+'i/iconos/iconContacto.png" alt="Contactanos" class="rollover bordeIMG" /></a>';
	
	/*<!--<a href="sitemap.php" id="sitemapIcon" title="Mapa del Sitio CentroPortugues.com"><img src="<?php echo RUTAABSOLUTAITEM; ?>i/iconos/iconMap.png" alt="Mapa del Sitio" class="rollover" /></a> -->*/

	return item;
};

jQuery(document).ready(function() {
	/*jcarousel*/
	$('#mycarousel').empty();
	$('#mycarousel').jcarousel({
		auto: 3,
		wrap: 'circular',
		animation: 1500,
		start: random2(1,2),
		visible: 3,
		scroll: 3,
		buttonNextHTML: '',
		buttonPrevHTML: '',
		initCallback: mycarousel_initCallback,
		itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });
});

jQuery(document).ready(function() {
	/*Item opciones header*/
	$("#header").find("#opcionessec").append(opcionesHeader());
	/*tooltip*/
	$(".eventosul a").append("<em></em>");
	$(".eventosul a").hover(function(){		
		var varTop = 15;
		if ($.browser.msie) varTop = 65;
		$(this).find("em").animate({opacity: "show", top: ""+varTop+""}, "slow");
		if ($(this).attr("title") != "")
		{
			var hoverText = $(this).attr("title");
			hoverText = sustituir(hoverText) + "</strong>";
			$(this).attr("title","");
			$(this).find("em").html(hoverText);
		};
	}, function() {
		var varTop = 35;
		if ($.browser.msie) varTop = 85;
		$(this).find("em").animate({opacity: "hide", top: ""+varTop+""}, "fast");
	});
	/* Target and Dummy # Link */
	$("a[@rel$='external']").click(function(){ this.target = "_blank"; });
	$("a[@href='#']").click(function(){ return false; });
	/*Fotos home jcycle*/
	$("#mainimage").find("#scrollimg").append(imagenesjCycle());
	/* SubMenu */
	$("#submenu a").mouseover(function(){ $(this).animate({ marginLeft:"6px" }, 300); }).mouseout(function(){ $(this).animate({ marginLeft:"0" }, 200);	});
	/*Texto Oculto*/
	var containers = $('div#maintexto > div');
    $('div#maintexto h3 a').click(function() {
        containers.slideUp(1000);
        return false;
    }).click();
	$('div#maintexto h3 a').click(function() {
        containers.slideUp(1000).filter(this.hash).slideDown(900);
        $('div#maintexto h3 a').removeClass('active');
        $(this).addClass("active");
        return false;
    });
	/* Oculta-Mostrar SubMenu */
	$('#cerrar').click(function() {        		
		var getWidth = $('#submenudiv').width();
		if (getWidth > 100) {
			$('#submenudiv').animate({width: "-=165px"}, 500);
			$('#submenu').hide();
			$('#cerrar').animate({left: "-=163px"}, 500).addClass('active');
			$('#mainContent').animate({left: "-=155px"}, 500);
			$('#maintexto').animate({width: "+=155px"}, 500);
			$('#mainContent h2').animate({width: "+=155px"}, 500);
		}
		else {
			$('#submenudiv').animate({width: "+=165px"}, 500);
			$('#submenu').show();
			$('#cerrar').animate({left: "+=163px"}, 500).removeClass('active');
			$('#mainContent').animate({left: "+=155px"}, 500);
			$('#maintexto').animate({width: "-=155px"}, 500);
			$('#mainContent h2').animate({width: "-=155px"}, 500);
		};
        return false;
    });
	/*Tabla zebra*/
	$(".stripeMe tr").mouseover(function() {$(this).addClass("over"); }).mouseout(function() {$(this).removeClass("over");});
	$(".stripeMe tr:even").addClass("alt");
	/*Header Opciones */
	$("#favoritoIcon").click(function() {bookmark();});
	/*$("#recomendarIcon img").mouseover(function() {$(this).attr('src','i/iconos/iconRecomendarOver.png');}).mouseout(function() {$(this).attr('src','i/iconos/iconRecomendar.png');});*/
});

/* Manejo de Tabs */
jQuery(document).ready(function() {
	if(!( $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent) )) {
		var tabContainers = $('div.tabs > div');
		$('div.tabs ul.tabNavigation a').click(function() {
			tabContainers.fadeOut(200).filter(this.hash).fadeIn(900);
			$('div.tabs ul.tabNavigation a').removeClass('selected');
			$(this).addClass('selected');
			return false;
		}).filter(':first').click();
	}
});

// Image Rollovers
var rollovers = function(){ $('img[@class*=rollover]').rollover(); }
jQuery.fn.rollover = function() {
	return this.each(
		function() {
			var srcString = this.src;
			var ext = srcString.substring(srcString.length - 4, srcString.length), name = srcString.substring(0, srcString.length - 4), overImage = name + 'Over' + ext;
			var img = new Image();	img.src = overImage;
			$(this).bind('mouseover',function(){ this.src = overImage; } );
			$(this).bind('mouseout',function(){ this.src = srcString; } );
		}
	)
}
$(document).ready(rollovers);

// Pop-up Windows by Size
var popWindows = function() { $('a[@class*=popup]').popwindow(); }
jQuery.fn.popwindow = function() {
	return this.each(
		function(){
			var dimensions = this.className.match(/[0-9]{1,4}x[0-9]{1,4}/) + '';
			var width = eval(dimensions.split('x')[0]);
			var height = eval(dimensions.split('x')[1]);
			
			if (width < 50 || width == null) width = 300;
			if (height < 50 || height == null) height = 300;
			
			$(this).bind('click',function() { window.open("" + this.href + "",null,'resizable=1, scrollbars=1, width=' + width + ', height=' + height); return false; })
		}
	)
}
$(document).ready(popWindows);

// Correct PNG Images for IE 6
var pngFix = {
	init : function() {
		var imgs = $("img[@src*=png]");
		imgs.each(
			function() {
				var newSrc = $(this).attr('src'), newID = $(this).attr('id'), newClass = $(this).attr('class'), newTitle = $(this).attr('alt'), newStyle = $(this).attr('style'), newAlign = $(this).attr('align'), newW = $(this).attr('width'), newH = $(this).attr('height'), dfilter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true,src='"+ newSrc +"',sizingMethod=image)";
				
				var span = document.createElement('span');
				$(span).attr({ 'id':newID, 'class':newClass, 'title':newTitle, 'style':newStyle });
				$(span).css({'display':'inline-block', 'background':'none', width:newW+'px', height:newH+'px', filter:dfilter});
				if( newAlign ) $(span).css({'float':newAlign});
				if( $(this).parent('a') ) $(span).css({'cursor':'hand'});
				$(this).after(span).remove();
			}
		)
	}
}
if( $.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent) )
	$(document).ready(pngFix.init);
	
/*
jQuery(document).ready(function() 
{ 
	if(!( $.browser.msie && /MSIE\s(5\.5)/.test(navigator.userAgent) ))
		$("a[@rel$='unica']").click(); 
});
*/	