/**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.fundacionsantateresa.org/','Fundacion Santa teresa');
	else {
		if (userAgent.indexOf("Firefox") != -1)
			window.sidebar.addPanel("Fundacion Santa teresa", "http://www.fundacionsantateresa.org/", "");	
		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>");
}

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/iphome/ip_home1.jpg" alt="" width="961" height="332" />';*/
	
	var num1 = random2(1, 43); //Se hayan los numeros de las imagenes a mostrar
	var num2 = random2(1, 43);
	var num3 = random2(1, 43);
	var num4 = random2(1, 43);
	//var num5 = random2(1, 43);
	
	while (num1 == num2)
		num2 = random2(1, 42);
		
	while (num1 == num3 || num2 == num3)
		num3 = random2(1, 42);
		
	while (num1 == num4 || num2 == num4 || num3 == num4)
		num4 = random2(1, 42);
		
	/*while (num1 == num5 || num2 == num5 || num3 == num5 || num4 == num5)
		num5 = random2(1, 42);*/
		
	imagenes = imagenes + '<img src="i/iphome/ip_home'+ num1 +'.jpg" alt="" width="961" height="332" />';
	imagenes = imagenes + '<img src="i/iphome/ip_home'+ num2 +'.jpg" alt="" width="961" height="332" />';
	imagenes = imagenes + '<img src="i/iphome/ip_home'+ num3 +'.jpg" alt="" width="961" height="332" />';
	imagenes = imagenes + '<img src="i/iphome/ip_home'+ num4 +'.jpg" alt="" width="961" height="332" />';
	//imagenes = imagenes + '<img src="i/iphome/ip_home'+ num5 +'.jpg" alt="" width="961" height="332" />';
			
	/*var i = 1;
	while (i < 44) 	{
		imagenes = imagenes + '<img src="i/iphome/ip_home'+ i +'.jpg" alt="" width="961" height="332" />';
		i++;
	}*/

	return imagenes;
};


jQuery(document).ready(function() {
	/* Target and Dummy # Link */
	$("a[@rel$='external']").click(function(){ this.target = "_blank"; });
	$("a[@href='#']").click(function(){ return false; });
	/*Header Opciones */
	$("#favoritoIcon").click(function() {bookmark();});
	/* Form Feedburner newsletter */
	$("form#newsletter").submit(function(){ this.target="popupwindow"; window.open('http://feedburner.google.com/fb/a/mailverify?uri=fstmail', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true; });
	/*Fotos home jcycle*/
	$("#subheader").find("#scrollimg").append(imagenesjCycle());
	$(".home #subheader").css("background","#fff");
	$("#particularForm").hide();
	$("#empresaForm").hide();
	$("#verparticularForm").click(function() { $("#particularForm").toggle("fast"); });
	$("#verempresaForm").click(function() { $("#empresaForm").toggle("fast"); });
	//$("verempresaForm").toggle("slow");
	/* Timeline */
	$("#timeline .item_historia a.preview").click(function() {return false;});
	//$("#timeline .item_historia").css({"width":"330px"});//,"cursor":"pointer"});
	//$("#timeline .item_historia p").hide();
	//$("#timeline .item_historia div.pestana").css({"marginLeft":"330px", "marginTop":"28px"});
	$("#timeline .item_historia div.pestana").css({"marginLeft":"0px", "marginTop":"-1px"});
	/*$("#timeline .item_historia div.pestana a").click(function() {
		$("#timeline .item_historia p").slideUp(1000);
		$("#timeline .item_historia").animate({width: "330px"}, 1000);				
		$(this).parent().animate({"opacity":"0"}, 0);
		$("#timeline .item_historia div.pestana").css({"marginLeft":"330px", "marginTop":"28px"});
		$(this).parent().animate({"marginLeft":"0px", "marginTop":"-1px"}, 0).animate({"opacity":"100"}, 1500);
		$(this).parent().parent().animate({width: "620px"}, 1000).find("p").slideDown(1000);		
		return false;
	}).filter(':first').click();*/
	/*Texto Oculto*/
	/*var containers = $('div#lado1 > dl');
	$('div#lado1 h4 a').click(function() {
        containers.hide().filter(this.hash).show();
        $('div#maintexto h4 a').removeClass('active');
        $(this).addClass("active");
        return false;
    }).filter(':first').click();*/
});

/* Manejo de Tabs */
jQuery(document).ready(function() {
	if(!( $.browser.msie && /MSIE\s(5\.5)/.test(navigator.userAgent) )) {
		var tabContainers = $('div.tabs > div');
		$('div.tabs ul.tabNavigation a').click(function() {
			tabContainers.fadeOut(200).filter(this.hash).fadeIn(1000);
			$('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[@class$='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);
	
$(document).ready(function(){
	$("#nav-one li").hover(
		function(){ $("ul", this).fadeIn("fast"); }, 
		function() { } 
	);
	if (document.all) {
		$("#nav-one li").hoverClass ("sfHover");
	}
});
	  
$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};	
