// JavaScript Document

function navinit(){
	$('.menu_item').live('click', function(){
		var locale = $(this).attr('id')
		window.location = locale
	})
	
	$('.sub_section_sub').live('click',function(){
		var parent = $(this).parent().attr("id")
		toggle_Box(parent)
	})
	
	$('.dj').live('click', function(){
		var tempid = $(this).attr("id")
		var temparray = tempid.split("_")
		dj_choose(temparray[0])
	})
	
	$('.sub_section_header span').live('click',function(){
		$('#1st').toggle("slide", {direction:"left"}, 1000)
		$('#2nd').toggle("slide", {direction:"right"}, 1000)
	})
	
	$('.weekday').live('click', function(){
		load_programs($(this).attr("id"))
	})
	
	$('#siembre').live('click', function(){
		modal_popup('ProclamaBannerFinal.jpg')
	})
	$('.modal').live('click', function(){
		var h = getDocHeight()
		var halfw = (window.screen.width/2)
		var halfh = (h/2)
		$('.modal img').fadeOut(1000).animate({left:halfw,right:halfw,top:halfh,bottom:halfh,width:'0px',height:'0px'},1000)
		$(this).animate({left:halfw,right:halfw,top:halfh,bottom:halfh,width:'0px',height:'0px'}, 1000)
		//$(this).fadeOut()
	})
	
	$('#left').live('click', function(){
		if($('#container .cditem:last-child').css("left") == "420px"){
			return false
		}else{
			$('.cditem').animate({'left' : '-=210px' })		
		}
	})
	$('#right').live('click', function(){
		if($('#container .cditem:first-child').css("left") == "0px" || $('#container .cditem:first-child').css("left") == "auto"){
			return false
		}else{
			$('.cditem').animate({'left' : '+=210px' })
		}
	})
	
	$('#eleft').live('click', function(){
		if($('#containerP .eventitem:last-child').css("left") == "0px"){
			return false
		}else{
			$('.eventitem').animate({'left' : '-=640.5px' })		
		}
	})
	$('#eright').live('click', function(){
		if($('#containerP .eventitem:first-child').css("left") == "0px" || $('#container .eventitem:first-child').css("left") == "auto"){
			return false
		}else{
			$('.eventitem').animate({'left' : '+=640.5px' })
		}
	})
	
	$('#dleft').live('click', function(){
		if($('.dj_show .dj_picture:first-child').css("left") == "0px" || $('.dj_show .dj_picture:first-child').css("left") == "auto"){
			return false
		}else{
			$('.dj_picture').animate({'left' : '-=640px' })		
		}
	})
	$('#dright').live('click', function(){
		var children1 = $('.dj_picture').children().length
		if($('.dj_picture:nth-child('+children1+')').css("left") == "0px" || $('.dj_picture:nth-child('+children1+')').css("left") == "auto"){
			return false
		}else{
			$('.dj_picture').animate({'left' : '+=640px' })
		}
	})
	
	$('.eventitem div img').live('click',function(){
		var height = getDocHeight()
		var width = (document.body.clientWidth/2)-248.5
		var doc = document.body.clientWidth
		var hdoc = (height/2)-288
		var cwidth = width+350
		var cheight = hdoc-15
		var bg = $(this).attr("alt")
		if(bg == ''){
			return false
		}else{
			$('body').append('<div id="shadowbox" style="height:'+height+'px;"><img id="closeShadow" style="position:absolute;z-index:100; cursor:pointer; left:'+cwidth+'px; top:'+cheight+'px;" src="images/close_small.png" /> <img style="position:absolute;z-index:99; border:3px solid #729225; left:'+width+'px; top:'+hdoc+'px;" src="' + bg + '" /><div>')
		}
	})
	
	$('#closeShadow').live('click', function(){
		//$(this).remove()
		$('#shadowbox').remove()
	})
	
	$('#shadowbox').live('click', function(){
		//$(this).remove()
		$('#fundinfo').remove()
		$('#pictures').css('display','none')
		$('#shadowbox').remove()
	})
	
	$('#closeall').live('click', function(){
		$('#fundinfo').remove()
		$('#pictures').css('display','none')
		$('#shadowbox').remove()
	})
	
	$('#fundadores').live('click',function(){
		var height = getDocHeight()
		var width = (document.body.clientWidth/2)-248.5
		var doc = document.body.clientWidth
		var hdoc = (height/2)-400
		var cwidth = width+350
		var cheight = hdoc-15
		$('body').append('<div id="shadowbox" style="height:'+height+'px;"></div>')
		var text = fundadores_show()
		$('body').append('<div id="fundinfo" style="z-index:91;top:'+hdoc+'px;left:'+width+'px;width:500px;position:absolute;font-size:12px;background-color:#394f11;color:#FFF;padding:10px;"><img id="closeall" style="position:absolute;z-index:100; cursor:pointer; left:500px; top:-20px;" width="35" src="images/close_small.png" />'+text+'</div>')
	})
	
	$('#donate').live('click',function(){
		var height = getDocHeight()
		var width = (document.body.clientWidth/2)-248.5
		var doc = document.body.clientWidth
		var hdoc = (height/2)-400
		var cwidth = width+350
		var cheight = hdoc-15
		$('body').append('<div id="shadowbox" style="height:'+height+'px;"></div>')
		var donateform = donate_form()
		$('body').append('<div id="fundinfo" style="z-index:91;top:'+hdoc+'px;left:'+width+'px;width:500px;height:400px;position:absolute;font-size:12px;background-image:url(images/offering_back.png);color:#FFF;padding:10px;"><img id="closeall" style="position:absolute;z-index:100; cursor:pointer; left:500px; top:-20px;" width="35" src="images/close_small.png" />'+donateform+'</div>')
	})
}

function dj_choose(dj){
	var djs = Array()
	$('.djs').each(function(){
		djs.push($(this).attr("id"))
	})
	var counted_djs = djs.length
	for(i=0;i<counted_djs;i++){
		$('#'+djs[i]).fadeOut(1500).css("display", "none")
	}
	$('.dj').css("background-color","#fd7e2a")
	$('#'+dj).fadeIn(1500).css("display", "block")
	$('#'+dj+'_click').css("background-color","#fff")
}

function rotating_sections(sectionid){
	var sections = new Array()
	$('#'+sectionid+' .sub_section_sub').each(function(sections){

	})
}

function load_section3(){
	var subsections = new Array()
	var i=0
	var current=''
	$('.section3 div').each(function(){
		subsections[i] = new Array()
		subsections[i]['id'] = $(this).attr('id')
		i++
	})
	for(i=0;i<subsections.length;i++){
		if($('#'+subsections[i]['id']).css("display") == 'block'){
			current=i
		}
	}
	if(current == subsections.length){
		next = 0;
	}else{
		next = i+1
	}
	currentsection = subsections[current]['id']
	$('#' + currentsection).css("display", "none")
	$('#' + subsections[next]['id']).toggle("slide", {direction:"right"}, 1000)
	
}

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function modal_popup(img){
	var image = 'bg'+img
	var h = getDocHeight()
	var halfw = (window.screen.width/2)
	var halfh = (h/2)
	var imgw = halfw-200
	var imgh = halfh-200
	$('.modal').html('<img src="images/'+image+'" border="0" style="display:none; position:absolute;" />')
	$('.modal').css("left", halfw)
	$('.modal').css("right", halfw)
	$('.modal').css("top", halfh)
	$('.modal').animate({left:'0px',right:'0px',top:'0px',height:getDocHeight(),width:'100%'},1000)
	$('.modal img').animate({left:imgw,top:imgh},1000).fadeIn(1000)
}

function donate_form(){
	var donate = '<table style="margin-left:35px; margin-top:60px;"><tr><td><FORM action="https://www.paypal.com/cgi-bin/webscr" method="post">'
	donate += '<INPUT TYPE="hidden" name="cmd" value=" _donations">'
	donate += '<input type="hidden" name="business" value="informacion@radiovida.com">'
	donate += 'First Name </td><td><input type="text" name="first_name"></td></tr><tr><td>'
	donate += 'Last Name </td><td><input type="text" name="last_name"></td></tr><tr><td>'
	donate += 'Billing Address </td><td><input type="text" name="address1"></td></tr><tr><td>'
	donate += 'City </td><td><input type="text" name="city"></td></tr><tr><td>'
	donate += 'State </td><td><input type="text" name="state" value="TX"></td></tr><tr><td>'
	donate += 'Zip </td><td><input type="text" name="zip"></td></tr><tr><td>'
	donate += 'Email Address </td><td><input type="email"></td></tr><tr><td>'
	donate += 'Amount </td><td><input type="text" name="amount" value="0.00"></td></tr><tr><td>'
	donate += '<input type="hidden" name="item_name" value="Online Donation">'
	donate += 'Payment Method </td><td><select name="method"><option selected value="CC">Credit Card<option></select></td></tr><tr>'
	donate += '<td colspan="2"><input type="submit" value="donate"></td></tr>'
	donate += '</form></table>'
	return donate
}

function fundadores_show(){
	var text = '<table border="0" cellspacing="0"><tr>'
	text += '<td><image width="150" style="background-color:#fff;" src="images/EnrigueyNormaGarza.png"><img width="150" style="background-color:#fff;" src="images/ElisasyCandyGarza.png" /><img width="150" style="background-color:#fff;" src="images/RosalioyAliciaMartinez.png" /></td>'
	text += '<td><p>Radio Vida nace primeramente en Dios Nuestro Se&ntilde;or, luego inquieta el coraz&oacute;n de Enrique Garza, Elias Garza y un servidor Rosalio Martinez. Juntos nos dimos a la tarea de informarnos, investigar y el convencimiento de que era necesario que se levantar&aacute; un nuevo ministerio Radial para servir a las iglesias evang&eacute;licas y ministerios del Se&ntilde;or.</p>'

	text += '<p>Enseguida logramos convencer a nuestras familias que se unieran con nosotros y finalmente a otros hermanos y ministerios de diferentes denominaciones que creyeron en el proyecto que presentabamos y que lo dabamos por hecho, ya que cada d&iacute;a confesabamos que lo lograriamos. Nombramos una mesa de direcci&oacute;n y asi nos registramos ante el gobierno 48 hermanos que conformamos la Asociacion Ministerios Cristianos del Valle. Orabamos juntos en todo tiempo y lugar, en estacionamientos de tiendas y en las labores donde ibamos a ver las antenas de otras difusoras. Una ma&ntilde;ana me llam&oacute; Enrique Garza para decirme que vend&iacute;an una difusora, y me dijo "&iquest;a que no sabe cual es?", y le dije "la que esta cerca de mi casa." El me pregunt&oacute; que como lo sab&iacute;a y la verdad es que los dos ya la hab&iacute;amos puesto en las manos de Dios, aunque nunca habiamos hablado de ella, pero el Se&ntilde;or ya la ten&iacute;a reservada para este ministerio.</p>'

	text += '<p>La historia es larga y bonita pasaron muchas otras cosas, pero para acabar pronto les dire que la enganchamos con 100,000.00 y el d&iacute;a 1 de Marzo de 1991 a las 6:00 a.m. Radio Vida KRGE 1290 AM estaba en nuestras manos, se abrieron los micr&oacute;fonos para la gloria de Dios. El prop&oacute;sito de esta difusora es servir a las iglesias, alentar a los creyentes con nuestra programaci&oacute;n, compartimos la doctrina de la biblia y evangelizamos desde la cabina de Radio Vida alegrando los corazones del pueblo de Dios con la m&uacute;sica selecta que se programa cada d&iacute;a para todas las edades. Amamos a nuestra gente, respetamos los ministerios serios y consagrados. y tenemos el deseo de servir a todos los hermanos que se acercan a nosotros.</p>'

	text += '<p>Radio Vida KRGE 1290 AM para la GLORIA DE DIOS!</p>'

	text += '<p>Rosalio Martinez</p></td>'
	return text
}
