﻿/***************************/
//@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;
var scoreQuerypopupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#main").css({
			"opacity": "0.4"
		});
		centerPopup();
		$("#howtoScore").fadeIn("slow");
		
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
	    $("#main").css({
	        "opacity": "1.0"
	    });

	    $("#howtoScore").fadeOut("slow");
		
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering5
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#howtoScore").height();
	var popupWidth = $("#howtoScore").width();
	//centering
	$("#howtoScore").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6

//	$("#main").css({
//		"height": windowHeight
//	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});


//Get Standings ajax
function tweetStanding() {
    $('#point').html("");
    $('#standing').html("");
    $('#pointHeading').html("");
    $('#standingHeading').html("");
    $('#pointHeading').html("One Moment Please");
    $.post("standings.aspx", { screenname: $("#TwitterUser").val() }, function(response) {

        index = response.indexOf(',');
        var point = response.substring(0, index);
        response = response.substring(1 + index);
        index = response.indexOf(',');
        var standing = response.substring(0, index);

        window.open('http://twitter.com/home?status=I%27m%20' + standing + '%20' + 'on%20Kiweets', 'twitter', 'menubar=1,resizable=1,scrollbars=1,location=1,status=1,width=800,height=600,resizable=yes'); 

        

    }, "text");
}



//Get Standings ajax
function getStandingForUser() {
    $('#point').html("");
    $('#standing').html("");
    $('#pointHeading').html("");
    $('#standingHeading').html("");
    $('#pointHeading').html("One Moment Please");
    $.post("standings.aspx", { screenname: $("#TwitterUser").val() }, function(response) {
        
        index = response.indexOf(',');
        var point = response.substring(0, index);
        response = response.substring(1 + index);
        index = response.indexOf(',');
        var standing = response.substring(0, index);

        $('#point').html(point);
        $('#standing').html(standing);
        $('#pointHeading').html("Points:");
        $('#standingHeading').html("Standing:");

    }, "text");
}


//loading popup with jQuery magic!
function scoreQueryloadPopup() {
    if (scoreQuerypopupStatus == 0) {
        $("#main").css({
            "opacity": "0.4"
        });
        scoreQuerycenterPopup();
        $("#scorequery").fadeIn("slow");

        scoreQuerypopupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function scoreQuerydisablePopup() {
    //disables popup only if it is enabled
    if (scoreQuerypopupStatus == 1) {
        $("#main").css({
            "opacity": "1.0"
        });

        $("#scorequery").fadeOut("slow");

        scoreQuerypopupStatus = 0;
    }
}

//centering popup
function scoreQuerycenterPopup() {
    //request data for centering5
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#scorequery").height();
    var popupWidth = $("#scorequery").width();
    //centering
    $("#scorequery").css({
        "position": "absolute",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });
    //only need force for IE6

    //	$("#main").css({
    //		"height": windowHeight
    //	});

}
