﻿// JavaScript Document
currentStatus=false;
$("document").ready(function(){
	
	setInterval(function(){ 
	if(currentStatus=="Online") 
		{
			$("#online .textonline").show();$("#online .textoffline").hide();
		}
		else 
		{
			$("#online .textonline").hide();$("#online .textoffline").show();
		}
	},1000);
	
	//preload
	var image1 = $('<img />').attr('src', 'images/venta_boton_on.png');
	var image2 = $('<img />').attr('src', 'images/venta_boton_on_s.png');
	

	$("#boton_venta2").hover(function(){$(this).attr("src","images/venta_boton_on.png");},function(){ $(this).attr("src","images/venta_boton_off.png");});
	
	
	$("#boton_venta").hover(function(){ $(this).attr("src","images/venta_boton_on.png");},function(){$(this).attr("src","images/venta_boton_off.png");}).click(vender);
	
	
	
	/* checkbox y radio click en la palabra a la derecha */
	/* para que funcione solo tengo que agregar los span a la derecha del input */
	/* ej: <input type....><span>texto</span> */	
	$("input:checkbox , input:radio").next("span").css("cursor","pointer").click(function(){$(this).prev("input").click()});

	automatic();
	flikr();
	
	});
	
	
	
	function flikr()
	{
				if($('#cbox').size()==0) return;
				$('#cbox').jflickrfeed({
			
				qstrings: {
					id: '59993709@N06',
					tags:'show'
				},
					limit: 100,
				itemTemplate:
				'<li>' +
					'<a rel="colorbox" href="{{image}}" title="{{title}}">' +
						'<img src="{{image_s}}" alt="{{title}}" />' +
					'</a>' +
				'</li>'
			}, function(data) {
				$('#cbox a').colorbox();
			});
			
			
	}
	
function automatic()
	{
		var a=$("#automatic").val();
		switch(a)
		{
			case 'login':
				if($("#key").val()>'')
				$('#logear').submit();
				else
				openLogin();
			break;
			case 'send':	
				vender();
			break;
			
			case 'video':	
				vervideo();
			break;
			
		}
	}
	
	
	
function vender(){
		
		$.facebox('<iframe width="600" height="380" frameborder="0" src="crear.php">');
		
		}
		
function openLogin(){
		
		$.facebox('<iframe width="450" height="315" frameborder="0" src="sitelogin.php">');
		
		}
		
function validarEmail(email) {
	
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
	return true;	
	else return false;
}		



function enviar() {


	var email=$.trim($("#email").val());
	$(".courv").html('').hide();
	if(!validarEmail(email))
	{
	envioError("El email está mal formulado !, corrígelo e inténtalo nuevamente.");
	return false;	
	}
	$("input").attr("disabled",true);
	envioOk("Enviando... aguarda un instante.");
	$.post("site.oper.php","oper=enviar&email="+$("#email").val(),function(x){
		
		if(x!='1')
		{ envioError(x);$("input").attr("disabled",false);}
		else
    	envioOk("Se ha enviado el email a tu correo, busca el email que te enviamos y dale click al vínculo indicado.");
		
		});
	
	}

function envioError(m)
{	
	$(".courvOk,img#bs").hide();
	$(".courv").hide().html(m).fadeIn(500); $("#email").focus();
}	

function envioOk(m)
{	
	$(".courv").hide();
	if(m==0)
	{
		$("img#bs").show();
	}
	else
	$(".courvOk").hide().html(m).fadeIn(500);
}


function vervideo()
{
	location.hash="video";	
	$.getScript('http://www.inmokey.com/admin/modules/livehelp/include/javascript.php');
		$.facebox('<iframe title="YouTube video player" width="640" height="390" src="http://www.youtube.com/embed/3ZTbjauWTSI" frameborder="0" allowfullscreen></iframe>');
		
		//$.facebox('<iframe id="cargavideo"  src="http://player.vimeo.com/video/21704831?title=0&amp;byline=0&amp;color=59a5d1&amp;autoplay=1" width="640" height="360" frameborder="0"></iframe>');
		
		//$.facebox("<iframe id='cargavideo' src='video/video.php' width='640' height='364' frameborder='0' style='border: 1px solid #ddd'></iframe>");
	
}


function newhash(x)
{
		location.hash=x;	
	$.getScript('http://www.inmokey.com/admin/modules/livehelp/include/javascript.php');
}


