$(document).ready(function(){
	// Add watermark in text fields						   
	$("#TxtUserName").blur().Watermark("Email", '#333');
	$("#TxtPassword").Watermark("Password", '#333');
	
	//--Check if user is already logged using session in index.php
	if (AlreadyLogged != ''){
		// If user get acces hide login form
		$('.Login').hide();
		//--Show Welcome Message---
		$('#WelcomeMsg, #LogOut').fadeIn();
	}
	
	$('#LoginForm').submit(function(){
		Login();
		// Prevent page postback
		return false;
	});
	
	$('.LnkHome').click(function(){
		$('#PnlIframe').hide();
	});
	$('.LnkAboutUs').click(function(){
		$('#PnlIframe iframe').attr('src','sub_pages/about_us.php');
		$('#PnlIframe').fadeIn();
	});
	$('#BtnSignup').click(function(){
		$('#PnlIframe iframe').attr('src','sub_pages/sign_up.php');
		$('#PnlIframe').fadeIn();
	});
	$('.LnkGallery').click(function(){
		if( RoleID == 2 || RoleID == 3  ){	
			$('#PnlIframe iframe').attr('src','sub_pages/gallery/gallery.php');
			$('#PnlIframe').fadeIn();
		}else{
			alert('Debe estar registrado para poder accesar esta seccion.')
			$('#PnlIframe iframe').attr('src','sub_pages/sign_up.php')
			$('#PnlIframe').fadeIn()
		}
	});
	$('.LnkEditorial').click(function(){
		if( RoleID == 2 || RoleID == 3  ){							  
			$('#PnlIframe iframe').attr('src','sub_pages/editorial/editorial.php');
			$('#PnlIframe').fadeIn();
		}else{
			alert('Debe estar registrado para poder accesar esta seccion.')
			$('#PnlIframe iframe').attr('src','sub_pages/sign_up.php')
			$('#PnlIframe').fadeIn()
		}
	});
	$('.LnkContactUs').click(function(){
		$('#PnlIframe iframe').attr('src','sub_pages/contact_us.php');
		$('#PnlIframe').fadeIn();
	});
	$('.LnkFindIt').click(function(){
		$('#PnlIframe iframe').attr('src','pdf/distribution_list.pdf')
		$('#PnlIframe').fadeIn()
	});
	$('.LnkRead').click(function(){
		if( RoleID == 2 || RoleID == 3 ){
			$('#PnlIframe iframe').attr('src','sub_pages/read_it.php');
			$('#PnlIframe').fadeIn();	
		}else{
			alert('Debe estar registrado para poder accesar esta seccion.')
			$('#PnlIframe iframe').attr('src','sub_pages/sign_up.php')
			$('#PnlIframe').fadeIn()
		}
	});
	
	$('.nyroModalSettingA').click(function(){
		NyroModalProperties(400, 300)								   
	});
	
	//--(SHOW TOOLTIPS)--
	$(".SectionTooltip").tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		extraClass: "pretty",
		fixPNG: true,
		opacity: 0.95,
		left: -120
	});
	
	//--(DROP SHADOWS)--
	$("div#Container, #Pnl7, #Pnl9, #Pnl10, #Pnl4, #Advertise li").dropShadow({left: 2, top: 2, opacity: 0.7, blur: 2});
	$(".ShadowHeader").dropShadow({left: 0, top: -17, opacity: 0.9, blur: 1});	 

});

function NyroModalProperties(width, height){
	$.nyroModalSettings({
		width: width, // default Width If null, will be calculate automatically
  		height: height, // default Height If null, will be calculate automatically
		modal: false, // Esc key or click backgrdound enabling or not
		bgColor: '#1E1D17'
	}); 
}

function Login(){
		$.ajax({
			type: "POST",
			url: "database/login.php",
			data: "email=" + $('#TxtUserName').val() + "&pass=" + $('#TxtPassword').val(),
			async: false, // Blocks the browser while the requests is active
			success:function(result){
				if (result == 'logged'){
					// If user get acces hide login form
					$('.Login').hide();
					//--Show Welcome Message---
					document.location = 'index.php'					
				}else{
					// Show login form
					$('.Login').fadeIn()
					$('#ErrorLogin').html(result)
					if( result == 'Email not found')
						$('#TxtUserName').val('').blur().focus()
					else if(result == 'Wrong password')
						$('#TxtPassword').val('').blur().focus()
					$('#WelcomeMsg').fadeOut().html('')
				}
			}
		});
}