var porId = {
	elegSitiLink : function(e){
		$('#elegSiti').fadeIn("slow");
		$('#elegSitiLink').fadeOut("slow");
	},
	oculSiti : function(){
		$('#elegSiti').fadeOut("slow");
		$('#elegSitiLink').fadeIn("slow");
	},
	linkCP: function(e){
		if (navigator.appName=="Netscape"){
			$('#linkCP').addClass(' acti');
			$('#CP').slideToggle();
			$('#linkMLP').removeClass('acti');
			$('#MLP').slideToggle();
		}
		else{
			$('#linkCP').addClass(' acti');
			$('#CP').show();
			$('#linkMLP').removeClass('acti');
			$('#MLP').hide();
		}
	},
	linkMLP: function(e){
		if (navigator.appName=="Netscape"){
			$('#linkMLP').addClass('acti');
			$('#MLP').slideToggle();
			$('#linkCP').removeClass('acti');
			$('#CP').slideToggle();
		}else{
			$('#linkMLP').addClass('acti');
			$('#MLP').show();
			$('#linkCP').removeClass('acti');
			$('#CP').hide();
		}
	},
	linkVali : function(){
		if ($('#oculVali').attr('style')=='display: none;' || $('#oculVali').attr('style')=='DISPLAY: none' ){
			$('#oculVali').show();
		}else{
			$('#oculVali').hide();
		}
	},
	cerrarVali :function(){
		if($.id('#cerrarVali')){
			$('#oculVali').hide();
		}
	}
}
var porSelect ={
	sitios : function(e){
		location.href=e.target.value;
	}
}
var Func = {
	google_analytics: function(page){
		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
		$.getScript(gaJsHost + 'google-analytics.com/ga.js', function(){
			var pageTracker = _gat._getTracker("UA-1694937-8");
				pageTracker._initData();
				pageTracker._trackPageview(page);
		});
	},
	Busc : function(){
		$('.BuscText').focus(function(){
       		if ($(this).val() == $(this)[0].title){
            	$(this).val('');
        	}
    	}); 
    	$('.BuscText').blur(function(){
        	if ($(this).val() == ''){
            	$(this).val($(this)[0].title);
        	}
    	});
    	$('.BuscText').blur();
	},
	OtrosSitios : function(){
		$('.OSitios ul a').attr({ target: '_blank' });
		$('.OSitios').hover(function() {
				$(this).find('a').stop(true, true).addClass('acti').next('div').show();
			},function(){
				$(this).find('a').stop(true, true).removeClass('acti').next('div').fadeOut('200'); 
		});
	},
	BannerHome : function(){
		$('ul#bannPP').innerfade({
			speed: 2000,
			timeout: 6000,
			type: 'random_start',
			containerheight: '175px'
		});
		//$('.bgBann').css({'opacity':.9});
	}
}
var randoms = {
	imagenes : function(){
		if ($.id('#sepaMas')) $('#sepaMas').attr('id', 'sepaMas'+parseInt(Math.random()*8+1));
		if ($.id('#cuenDos')) $('#cuenDos').attr('id', 'cuenDos'+parseInt(Math.random()*6+1));
		if ($.id('#finaA')) $('#finaA').attr('id', 'finaA'+parseInt(Math.random()*5+1));
		if ($.id('#finaB')) $('#finaB').attr('id', 'finaB'+parseInt(Math.random()*5+1));
		if ($.id('#clieA')) $('#clieA').attr('id', 'clieA'+parseInt(Math.random()*5+1));
		if ($.id('#clieB')) $('#clieB').attr('id', 'clieB'+parseInt(Math.random()*5+1));
		if ($.id('#otroA')) $('#otroA').attr('id', 'otroA'+parseInt(Math.random()*5+1));
		if ($.id('#otroB')) $('#otroB').attr('id', 'otroB'+parseInt(Math.random()*5+1));

		var rndA = parseInt(Math.random()*2+1);
		var rndB = parseInt(Math.random()*4+1);
		var rndC = parseInt(Math.random()*4+1);
		var rndD = parseInt(Math.random()*4+1);
		var rndO = parseInt(Math.random()*1+1);
		// textos bneficios
		if ($.id('#beneChil')) {
			if (rndB==1) $('#beneChil').html('<ul><li><a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Financiamiento+Pyme/Capital+Corto+Plazo/Factoring/" title="Factoring Fogape" rel="Content">Factoring Fogape</a></li><li><a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Financiamiento+Pyme/Capital+Mediano+y+Largo+Plazo/Creditos/Corfo/Credito+Corfo+B15/" title="Cr&eacute;dito Corfo B15" rel="Content">Cr&eacute;dito Corfo B15</a></li><li><a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Financiamiento+Pyme/Capital+Mediano+y+Largo+Plazo/Leasing/" title="Leasing" rel="Content">Leasing</a></li></ul>');
			if (rndB==2) $('#beneChil').html('<ul><li><a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Financiamiento+Pyme/Capital+Mediano+y+Largo+Plazo/Creditos/Corfo/Credito+o+Leasing+Corfo+Inversion/" title="Cr&eacute;dito Corfo Inversi&oacute;n" rel="Content">Cr&eacute;dito Corfo Inversi&oacute;n</a></li><li><a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Financiamiento+Pyme/Capital+Corto+Plazo/Tarjetas+de+creditos/" title="Tarjetas de cr&eacute;dito" rel="Content">Tarjetas de cr&eacute;dito</a></li><li><a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Financiamiento+Pyme/Capital+Mediano+y+Largo+Plazo/Creditos/Corfo/Credito+Corfo+B22/" title="Cr&eacute;dito Corfo B22" rel="Content">Cr&eacute;dito Corfo B22</a></li></ul>');
			if (rndB==3) $('#beneChil').html('<ul><li><a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Financiamiento+Pyme/Capital+Mediano+y+Largo+Plazo/Creditos/Corfo/Credito+Corfo+B11/" title="Cr&eacute;dito Corfo B11" rel="Content">Cr&eacute;dito Corfo B11</a></li><li><a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Cliente+PYME/Abono+Express/" title="Abono Express" rel="Content">Abono Express</a></li><li><a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Financiamiento+Pyme/Capital+Mediano+y+Largo+Plazo/Creditos/Fogape/" title="Cr&eacute;dito Fogate" rel="Content">Cr&eacute;dito Fogate</a></li></ul>');
			if (rndB==4) $('#beneChil').html('<ul><li><a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Financiamiento+Pyme/Capital+Mediano+y+Largo+Plazo/Creditos/Corfo/Credito+Corfo+B14/" title="Cr&eacute;dito Corfo B14" rel="Content">Cr&eacute;dito Corfo B14</a></li><li><a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Financiamiento+Pyme/Capital+Mediano+y+Largo+Plazo/Creditos/Corfo/Credito+o+Leasing+Corfo+Inversion/" title="Cr&eacute;dito Corfo Inversi&oacute;n" rel="Content">Cr&eacute;dito Corfo Inversi&oacute;n</a></li><li><a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Cliente+PYME/Abono+Express/" title="Abono Express" rel="Content">Abono Express</a></li></ul>');
		}

		// banners
		if(rndA==1 && $.id('#bannRand')) $('#bannRand').html('<p class="botoSide queBanc"><a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Cliente+PYME/Banconexion/" title="&iquest;Qu&eacute; es Banconexi&oacute;on?"><strong>&iquest;Qu&eacute; es Banconexi&oacute;on?</strong></a></p>');
		if(rndA==2 && $.id('#bannRand')) $('#bannRand').html('<p class="botoSide seguBanc"><a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Cliente+PYME/Banconexion/" title="Seguridad en Banconexi&oacute;n"><strong>Seguridad en Banconexi&oacute;on</strong></a></p>');

// 		if (navigator.appName=="Netscape"){
			// banners random big
			if ($.id('#xpliBig')) {
				if (rndC==1) $('#xpliBig').html('<a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Xplicas/Digipass/paso1?keepThis=true&TB_iframe=true&height=470&width=685" title="DIGIPASS, &iquest;Qu&eacute; es y para qu&eacute; sirve? Averigualo en 5 pasos." rel="help" class="thickbox xpliDigi">DIGIPASS, &iquest;Qu&eacute; es y para qu&eacute; sirve? Averigualo en 5 pasos.</a>');
				if (rndC==2) $('#xpliBig').html('<a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Xplicas/Cice/paso1?keepThis=true&TB_iframe=true&height=470&width=685" title="CICE, &iquest;Qu&eacute; es? Averigua c&oacute;mo puede servirle a tu empresa." rel="help" class="thickbox  xpliCice" >CICE, &iquest;Qu&eacute; es? Averigua c&oacute;mo puede servirle a tu empresa.</a>');
				if (rndC==3) $('#xpliBig').html('<a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Xplicas/Banconexion/paso1?keepThis=true&TB_iframe=true&height=470&width=685" title="BANCONEXION, Todo lo que necesitas saber para acceder a Banconexi&oacute;n." rel="help" class="thickbox xpliBanc" >BANCONEXION, Todo lo que necesitas saber para acceder a Banconexi&oacute;n.</a>');
				if (rndC==4) $('#xpliBig').html('<a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Xplicas/Financiamiento/paso1?keepThis=true&TB_iframe=true&height=470&width=685" title="FINANCIAMIENTO, resuelve tus dudas sobre intereses, documentaci&oacute;n y tipos de financiamiento." rel="help" class="thickbox xpliFina" >FINANCIAMIENTO, resuelve tus dudas sobre intereses, documentaci&oacute;n y tipos de financiamiento.</a>');
				$.getScript("/wps/wcm/resources/file/ebef80403a423ea/thickbox.js")
			}
			// banners random small
			if ($.id('#xpli')) {
				if (rndD==1) $('#xpli').html('<a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Xplicas/Digipass/paso1?keepThis=true&TB_iframe=true&height=470&width=685" title="DIGIPASS, &iquest;Qu&eacute; es y para qu&eacute; sirve? Averigualo en 5 pasos." class="thickbox xpliDigi" rel="help">DIGIPASS, &iquest;Qu&eacute; es y para qu&eacute; sirve? Averigualo en 5 pasos.</a>');
				if (rndD==2) $('#xpli').html('<a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Xplicas/Cice/paso1?keepThis=true&TB_iframe=true&height=470&width=685" title="CICE, &iquest;Qu&eacute; es? Averigua c&oacute;mo puede servirle a tu empresa." class="thickbox xpliCice"  rel="help">CICE, &iquest;Qu&eacute; es? Averigua c&oacute;mo puede servirle a tu empresa.</a>');
				if (rndD==3) $('#xpli').html('<a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Xplicas/Banconexion/paso1?keepThis=true&TB_iframe=true&height=470&width=685" title="BANCONEXION, Todo lo que necesitas saber para acceder a Banconexi&oacute;n." class="thickbox xpliBanc" rel="help">BANCONEXION, Todo lo que necesitas saber para acceder a Banconexi&oacute;n.</a>');
				if (rndD==4) $('#xpli').html('<a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Xplicas/Financiamiento/paso1?keepThis=true&TB_iframe=true&height=470&width=685" title="FINANCIAMIENTO, resuelve tus dudas sobre intereses, documentaci&oacute;n y tipos de financiamiento." class="thickbox xpliFina" rel="help">FINANCIAMIENTO, resuelve tus dudas sobre intereses, documentaci&oacute;n y tipos de financiamiento.</a>');
				$.getScript("/wps/wcm/resources/file/ebef80403a423ea/thickbox.js")
			}
			if ($("*").hasClass('botoOfer')) {
				if (rndO==1) $('.botoOfer').html('<a href="/wps/wcm/connect/BancoDeChile/ChilePYME/Campanas/Financiamientos-a-la-medida" title="Abrimos nuestras puertas para apoyar a las Pymes" class="camp01 ga"><span>Abrimos nuestras puertas para apoyar a las Pymes</span></a>');
			}
// 		}
	}
}
$(function() {//funcion similar window.onload, detecta cuando la estructura DOM se se carga completamente
	randoms.imagenes()
	$('.hide').hide();
	$('.show').show();
	Func.google_analytics('');
	$('.ga').bind("click", function(page){Func.google_analytics(this.rel); return;});
	Func.Busc();
	Func.OtrosSitios();
	Func.BannerHome();
	if($('#cont').height()<440 && $('#subi')){ $('#subi').hide();};
	if($('#AreaMedLargPlazo')){
		$('#AreaMedLargPlazo #linkMLP').addClass('acti');
		$('#AreaMedLargPlazo #MLP').show();
		$('#AreaMedLargPlazo #linkCP').removeClass('acti');
		$('#AreaMedLargPlazo #CP').hide();
	}

	$.each(porSelect, function (i) { //detecta eventos al hacer change sobre un elemento select
		if ($.isFunction(porSelect[i]) && $.id("#"+i)){
			$("#"+i).bind("change", function(e){eval("porSelect."+i+"(e)");});
		}
	});

	$.each(porId, function (i) {//detecta eventos al hacer click sobre un elemento con id presente en el objeto porid
		if ($.isFunction(porId[i]) && $.id("#"+i) ){
			$('#'+i).bind("click", function(e){eval("porId."+i+"(e)"); return false; });
		}
	});
});

jQuery.extend({ //extension de metodo jQuery
	id : function(id) {
		var id = id.split("#");
		return document.getElementById(id[1])?true:false;
	}
});
/*
Por Ayerviernes,
Max Villegas
*/