$(document).ready(function(e) {
	var screenMode = screen.width/screen.height;
	var Bgr16 = [
		{url: BASEURL + "images/background22.jpg"},
		{url: BASEURL + "images/background33.jpg"}
		
	]
	var Bgr4 = [
		{url: BASEURL + "images/background2.jpg"},
		{url: BASEURL + "images/background3.jpg"}
	]
	if(screenMode > 1.5) {
		pic2= new Image(1500,844); 
		pic2.src=BASEURL + "images/background11.jpg";
		pic4= new Image(1500,844); 
		pic4.src=BASEURL + "images/background22.jpg";
		pic6= new Image(1500,844); 
		pic6.src=BASEURL + "images/background33.jpg";
		var randNr = Math.floor((2)*Math.random());
		//console.log(randNr);
		$('#bgrImg').attr('src',Bgr16[randNr]['url']);
		
	}
	if(screenMode < 1.5) {
		pic1= new Image(1500,1125); 
		pic1.src=BASEURL + "images/background1.jpg";
		pic3= new Image(1500,1125); 
		pic3.src=BASEURL + "images/background2.jpg";
		pic5= new Image(1500,1125); 
		pic5.src=BASEURL + "images/background3.jpg";
		var randNr = Math.floor((2)*Math.random());
		$('#bgrImg').attr('src',Bgr4[randNr]['url']);
	}
	if(invalid_credentials == "1") {
		$(".invalid").css('visibility', 'visible');
	} else {
		$(".invalid").css('visibility', 'hidden');
	}
	
	if(invalid_credentials == "2") {
		 $('#dialogaccountinvalid').dialog({
            width: 560,
            height: 457,
            draggable: false,
            position: ['center', 54],
            show: 'blind',
			hide: 'blind',
            buttons: {
                'Close': function() {
                    $(this).dialog('close');
                }
            }
        });
        $('#dialogaccountinvalid').dialog('open');
	} 
	
	
	
$(window).bind('resize', fitBg);
$(window).trigger('resize');
    $('.loginContentRightOff').fadeTo('fast', 0);
    $('.loginContentLeftOff').fadeTo('fast', 0);

    $('.loginContentLeft').mouseover(function() {
        $('.loginContentLeftOff').fadeTo(300, 0, function() {
            $('.loginContentRightOff').fadeTo(300, 0.5, function() {
                $('.loginContentLeftPadding').css('z-index', '10');
                $('.loginContentLeftOff').css('z-index', '1');
                $('.loginContentRightPadding').css('z-index', '1');
                $('.loginContentRightOff').css('z-index', '10');
            });
        });
    });
    $('.loginContentRight').mouseover(function() {
        $('.loginContentLeftOff').fadeTo(300, 0.5, function() {
            $('.loginContentRightOff').fadeTo(300, 0, function() {
                $('.loginContentLeftPadding').css('z-index', '1');
                $('.loginContentLeftOff').css('z-index', '10');
                $('.loginContentRightOff').css('z-index', '1');
                $('.loginContentRightPadding').css('z-index', '10');
            });
        });
    });

    forgot_password_html = "<div style=\"text-align:center;margin:50px;\"><img src=\"" + BASEURL + "images/popup_logo.png\"/></div>";
    forgot_password_html += "<div style=\"text-align:center;margin:50px;\">If you've forgotten your password, enter your e-mail address below and we'll send you an e-mail message containing your new password.";
    forgot_password_html += "<br/><br/><br/>";
    forgot_password_html += "<div style=\"height:18px; width:430px; \"><span style=\"float:left; line-height:18px;\">E-Mail Address</span><input type='text' class='inputType' name='forgotten_email_address' id='forgotten_email_address'/></div>";
    forgot_password_html += "</div>";

    $(".signInBtn").click(function() {
        $("#login_form").submit();
    });
    $("#login_form").validate({
        rules: {
            email: {
                required: true,
                email: true
            },
            password: {
                required: true
            }
        }
    });




    $('#forgot_password').click(function() {

        $('#dialogopasswordforgotten').html(forgot_password_html);

        $('#dialogopasswordforgotten').dialog({
            width: 560,
            height: 457,
            draggable: false,
            position: ['center', 54],
            show: 'blind',
			hide: 'blind',
            buttons: {
                'Close': function() {
                    $(this).dialog('close');
                },
                'Send email': function() {
                	send_email();
                }
            }
        });
        $('#dialogopasswordforgotten').dialog('open');
    });
	
    $('#dialogopasswordforgotten').bind('keypress', function(e){
        if (e.keyCode == 13) {
           send_email();
        }
    });

});

function send_email(){
    $.ajax({
        type: "POST",
        url: BASEURL + "login/reset_password",
        cache: false,
        data: "email=" + $("#forgotten_email_address").val(),
        success: function(msg){
            if (msg.status == 1) {
                //show success message
                $("#dialogopasswordforgotten").html("<div style=\"text-align:center;margin:50px;\"><img src=\"" + BASEURL + "images/popup_logo.png\"/></div><center> A new password has been sent to your e-mail address.</center><br />");
                $("#dialogopasswordforgotten").dialog("option", "buttons", {
                    "Ok": function(){
                        $(this).dialog("close");
                    }
                });
                //change buttons 
            }
            else {
                $("#dialogopasswordforgotten").html(forgot_password_html + "<br /><center><h1 style='font-size: 10px; color: rgb(255, 0, 0);'>Your E-Mail Address does not appear to be valid - please make any necessary corrections.</h1></center>");
                //show failure message
            }
        }
    });
}

$(function(){
    // OPACITY OF BUTTON SET TO 50%
    $("#fade1").css("opacity", "1.0");
    
    // ON MOUSE OVER
    $("#fade1").hover(function(){
    
        // SET OPACITY TO 100%
        $(this).stop().animate({
            opacity: 1.0
        }, "fast");
    },    // ON MOUSE OUT
    function(){
        // SET OPACITY BACK TO 50%
        $(this).stop().animate({
            opacity: 0.5
        }, "fast");
    });
});

$(function(){
    // OPACITY OF BUTTON SET TO 50%
    $("#fade2").css("opacity", "0.5");
    
    // ON MOUSE OVER
    $("#fade2").hover(function(){
    
        // SET OPACITY TO 100%
        $(this).stop().animate({
            opacity: 1.0
        }, "fast");
    },    // ON MOUSE OUT
    function(){
        // SET OPACITY BACK TO 50%
        $(this).stop().animate({
            opacity: 0.5
        }, "fast");
    });
});

$(function(){
    // OPACITY OF BUTTON SET TO 50%
    $("#text p").css("opacity", "0.5");
    
    // ON MOUSE OVER
    $("#text p").hover(function(){
    
        // SET OPACITY TO 1000%
        $(this).stop().animate({
            opacity: 1.0
        }, "slow");
    },    // ON MOUSE OUT
    function(){
    
        // SET OPACITY BACK TO 50%
        $(this).stop().animate({
            opacity: 0.5
        }, "slow");
    });
});


$(function(){
    // OPACITY OF BUTTON SET TO 50%
    $("#div").css("opacity", "0.5");
    
    // ON MOUSE OVER
    $("#div").hover(function(){
    
        // SET OPACITY TO 100%
        $(this).stop().animate({
            opacity: 1.0
        }, "slow");
    },    // ON MOUSE OUT
    function(){
    
        // SET OPACITY BACK TO 50%
        $(this).stop().animate({
            opacity: 0.5
        }, "slow");
    });
});

function fitBg () {
	if ($('#bgCont img').height() == 0 || $('#bgCont img').width() == 0) {
  setTimeout(function() { $(window).trigger('resize'); }, 100);
  return;
}
    if ($('#bgCont').hasClass('h')) {
      if ($('#bgCont img').height() < $('#bgCont').height()) {
        $('#bgCont').attr('class','v');
        $('#bgCont img').css('marginLeft', -1 * parseInt($('#bgCont img').width() / 2));
      }
    } else {
      if ($('#bgCont img').width() < $('#bgCont').width()) {
         $('#bgCont').attr('class','h');
        $('#bgCont img').css('marginLeft', 0);
      }
    }
}
