//$(document).ready(function(){
//      $('.related-tweets').relatedTweets({
//         debug:true
//         ,from_users:'VMukti,hardiksa'
//         ,status:1
//         ,realtime:1
//         ,n:10
//         ,show_author:0
//		 ,show_avatar:1
//      });
//   });

function slideSwitch() {
    var $active = $('#slideshow IMG.active');
    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 500, function() {
            $active.removeClass('active last-active');
        });
}
$(function() {
    setInterval( "slideSwitch()", 2000 );
});


////////////////////////////////////////////


//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = {};

//loading popup with jQuery magic!
function loadPopup(popupId){
    //loads popup only if it is disabled
    if(popupStatus[popupId]==0){
        $(".backgroundPopup").css({
            "opacity": "0.7"
        });
        $(".backgroundPopup").fadeIn("fast");
        $("#" + popupId).fadeIn("fast");
        popupStatus[popupId] = 1;
    }
}

//disabling popup with jQuery magic!
function disablePopup(popupId){
    //disables popup only if it is enabled
    if(popupStatus[popupId]==1){
        $(".backgroundPopup").fadeOut("fast");
        $("#" + popupId).fadeOut("fast");
        popupStatus[popupId] = 0;
    }
}

//centering popup
function centerPopup(popupId){
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#" + popupId).height();
    var popupWidth = $("#" + popupId).width();
    //centering
    $("#" + popupId).css({
        "position": "absolute",
        "top": windowHeight/2-popupHeight/2,
        "left": windowWidth/2-popupWidth/2
    });
    //only need force for IE6

    $(".backgroundPopup").css({
        "height": windowHeight
    });

}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
    popupStatus = { one: 0, two: 0 };


    //LOADING POPUP
    //Click the button event!
    $(".button").click(function(){
        var popupId = $(this).attr("popup");
        //centering with css
        centerPopup(popupId);
        //load popup
        loadPopup(popupId);
    });

    //CLOSING POPUP
    //Click the x event!
    $(".popupContactClose").click(function(){
        var popupId = $(this).parents("div").attr("id");
        disablePopup(popupId);
    });
    //Click out event!
    $(".backgroundPopup").click(function(){
        // close any that are open
        for (var popupId in popupStatus)
        {
          if (popupStatus[popupId] == 1)
            disablePopup(popupId);
        }
    });
    //Press Escape event!
    $(document).keypress(function(e){
        var popupId = $(e.target).parents("div.popupContact").attr("id");
        if(e.keyCode==27 && popupStatus[popupId]==1){
            disablePopup(popupId);
        }
    });

});
