﻿
function popup(handle, id, close_id, bg_id, open) {		this.handle = document.getElementById(handle);	this.id = document.getElementById(id);	this.close_id = document.getElementById(close_id);	this.bg_id = document.getElementById(bg_id);	this.popupstatus = 0;	var that = this;	var jId = $("#"+id);	var jClose_id = $("#"+close_id);	var jBg_id = $("#"+bg_id);	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jId.height();
	var popupWidth = jId.width();
	
	jBg_id.css (
		{
			"opacity": "0.4"
		}
	);
	
	jId.css (
		{
			"position": "absolute",
			"top": windowHeight/2-popupHeight/2,
			"left": windowWidth/2-popupWidth/2
		}
	);

	jBg_id.css (
		{
			"height": windowHeight
		}
	);	
	
	if(this.handle != null)
	{		this.handle.onclick = function()
		{
			that.open_popup();
		}
	}	
			
	if(open == true)
	{
		this.popupstatus = 1;
		this.bg_id.style.display = '';
	}
	else
	{
		this.id.style.display = 'none';
	}
	
	this.open_popup = function() {		if(that.popupstatus == 0) {			that.popupstatus = 1;						jBg_id.fadeIn("slow");			jId.fadeIn("slow");		}	};		this.close_id.onclick = function()
	{
		that.close_popup();
	}
	
	this.close_popup = function()	{		if(that.popupstatus == 1) {			that.popupstatus = 0;						jBg_id.fadeOut("slow");			jId.fadeOut("slow");		}	}}
function playSound(i){	
	if(window.sound) window.document["sound"].SetVariable("playsound", i);
	if(document.sound) document.sound.SetVariable("playsound", i);
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});


});


$(function(){ 
	// find all the input elements with title attributes
	$('input[title!=""]').hint();
});
(function ($) {

$.fn.hint = function (blurClass) {
  if (!blurClass) { 
    blurClass = 'blur';
  }
    
  return this.each(function () {
    // get jQuery version of 'this'
    var $input = $(this),
    
    // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = $(this.form),
      $win = $(window);

    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('').removeClass(blurClass);
      }
    }

    // only apply logic if the element has the attribute
    if (title) { 
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title
      
      // clear the pre-defined text when form is submitted
      $form.submit(remove);
      $win.unload(remove); // handles Firefox's autocomplete
    }
  });
};

})(jQuery);


