﻿/***************************/
//@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 proj_id = 0;
var inIframe = false;

//loading popup with jQuery magic!
function loadPopup() {
  //loads popup only if it is disabled
  if ($j('#hidPopupStatus').attr('value') == 0) {
    $j("#popupBackground").css({
      "opacity": "0.7"
    });
    $j("#ifrmProject").attr("src", "/content/project/?pid=" + proj_id);
    $j("#popupBackground").fadeIn("fast");
    $j("#popupWindow").fadeIn("fast");
    $j('#hidPopupStatus').attr('value', 1);
  }
}

function loadUploadPopup() {
  $j("#popupBackground").css({
    "opacity": "0.7"
  });
  $j("#popupBackground").fadeIn("fast");
  $j("#popupWindow").fadeIn("fast");
}

//disabling popup with jQuery magic!
function disablePopup() {
  //disables popup only if it is enabled
  var hid;
  var win;
  var bak;
  
  if (inIframe) {
    hid = $j("#hidPopupStatus", top.document);
    win = $j("#popupWindow", top.document);
    bak = $j("#popupBackground", top.document);
  }
  else {
    hid = $j("#hidPopupStatus");
    win = $j("#popupWindow");
    bak = $j("#popupBackground");
  }

  if (hid.attr('value') == 1) {
    win.fadeOut("fast");
    bak.fadeOut("fast");
    hid.attr('value', 0);
  }
}

//centering popup
function centerPopup() {
  //request data for centering
  var windowHeight = $j("#wrapper").height();
  
  //centering
  $j("#popupWindow").css({
    "position": "absolute",
    "top": 80,
    "left": 30
  });
  
  //only need force for IE6
  $j("#popupBackground").css({
    "height": windowHeight
  });
}

function openPopup(pid) {
  proj_id = pid; 
}

//CONTROLLING EVENTS IN jQuery
$j(document).ready(function() {

  //LOADING POPUP
  //Click the button event!
  $j(".project_picker_group").click(function(e) {
    //centering with css
    centerPopup();
    //load popup
    loadPopup();
  });

  //CLOSING POPUP
  //Click the x event!
  $j("#popupProjectClose").click(function() {
    disablePopup();
  });
  //Click out event!
  $j("#popupBackground").click(function() {
    disablePopup();
  });
  //Press Escape event!
  $j(document).keypress(function(e) {
    if (e.keyCode == 27 && $j('#hidPopupStatus').attr('value') == 1) {
      disablePopup();
    }
  });


});