﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$(".lightbox-fader").css({
			"opacity": "0.7"
		});
		$(".lightbox-fader").fadeIn("slow");
		$("#login-popup").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$(".lightbox-fader").fadeOut("slow");
		$("#login-popup").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#login-popup").height();
	var popupWidth = $("#login-popup").width();
	//centering
	$("#login-popup").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$(".lightbox-fader").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
    

    
$('#field4').focus(function(){
if($('#field4').val()=='login') {
    $('#field4').val('');
}
    });
    
$('#field3').focus(function(){
if($('#field3').val()=='password') {
    $('#field3').val('');
}     
    });
    
    
	//LOADING POPUP
	//Click the button event!
	$("#close").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
        return false;
	});
				
	//CLOSING POPUP
	//Click the x event!
	$(".box-close a").click(function(){
		disablePopup();
                return false;
	});
	//Click out event!
	$(".lightbox-fader").click(function(){
		disablePopup();
                return false;
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
    
    
    $('#enter').click(function() {
            $('#login-popup ul').html('<li><img src="assets/templates/rost21/images/ajax-loader.gif" id="loading" /></li>');
            
                var login = $('#field4').val();
                var password = $('#field3').val();
                
                $.ajax({
                    url: 'index-ajax.php',
                    type: 'POST',
                    data: 'q=assets/snippets/ajaxsnippet/ajaxsnippet.php &login=' + login + '&password=' + password,
                    
                    success: function(result) {
                      
                        
                        
                        // alert(result);
                    if(result==0) window.location = $('#loginredirect').html();
    
                      if(result==1) error = $('#loginerror').html();  
                      
                      if(result==2) error = $('#loginblock').html();  
                     
                     $('#login-popup ul').hide(500, function() {
                            $(this).html('<li>'+ error +'</li>');
                            $('#login-popup ul').show(500);
                        });
                        
                  // $('#login-popup ul li').fadeIn();   
                      
                        
                        // $('#login-popup ul').html('<li>' + result + '</li>');
                       // $('#response').remove();
                       // $('#container').append('<p id="response">' + result + '</p>');
                       // $('#loading').fadeOut(500, function() {
                       //     $(this).remove();
                       // });
                        
                    }
                });
                
                return false;
            });
    

});
