
/**
 * Defines the basic js functions of the frontend pages
 *
 * [2007-04-25 as] created
 *
 * $Rev: 1109 $     Revision of last commit
 * $Author: jan $  Author of last commit
 * $Date: 2009-06-26 15:09:18 +0200 (Fr, 26 Jun 2009) $    Date of last commit
 */

/**
 *	Describe the shop state
 */
var shop = new Boolean(false);

/**
 * Path singleton
 */
var path = {
	editorial_video: "http://simfylive.de/_videos_inc/editorial/",
	editorial_audio: "http://simfylive.de/_audio/editorial/",
	editorial_img: "http://simfylive.de/_img/editorial/",
	rel2root: "/",
	web_root: "http://simfylive.de/",
	file_root: "/usr/www/users/simfyl/live/",
	img_root: "http://simfylive.de/_img/",
	rel2root_cps: "/cps/",
	web_root_cps: "http://simfylive.de/cps/",
	file_root_cps:"/usr/www/users/simfyl/live/cps/",
	img_root_cps: "http://simfylive.de/cps/_img/"
}

/**
 * Opens a certain popup
 *
 * [2007-04-25 as] created
 *
 * @since 0.1
 */
function openPopup(content, name, width, height)
{
  var fenster = window.open(content, name,'width='+width+',height='+height+',left=100,top=100,margin=0,scrollbars=0,location=0,menubar=0,resizable=1,status=0,toolbar=0');
}

/**
 * Opens a certain popup with scrollbars
 *
 * [2007-11-21 as] created
 *
 * @since 0.1
 */
function openScrollPopup(content, name, width, height)
{
  var fenster = window.open(content, name,'width=' + (parseInt(width) + 20) + ',height=' + (parseInt(height) + 5) + ',left=100,top=100,margin=0,scrollbars=1,location=0,menubar=0,resizable=1,status=0,toolbar=0');
}


/**
 * Opens a floater
 *
 * [2007-08-14 as] created
 *
 * @since 0.1
 */
function showFloater(id, text, width, left, top)
{
  var floater = document.getElementById(id);

	floater.innerHTML = text;
  floater.style.width = width;
  floater.style.left = left;
  floater.style.top = top;
  floater.style.visibility = "visible";
}


/**
 * Opens a floater
 *
 * [2007-08-14 as] created
 *
 * @since 0.1
 */
function showFloaterBottom(id, text, width, left, top)
{
  var floater = document.getElementById(id);

  if(text.length > 0) {
		floater.innerHTML = text;
  }
  floater.style.width = width;
  floater.style.left = left;
  floater.style.bottom = top;
  floater.style.visibility = "visible";
  floater.style.display = "block";
}

/**
 * Check if user really wants to delete or remove item
 *
 * [2007-08-29 as] created
 *
 * @since 0.1
 */
function confirmDelete(target, text)
{
  check = confirm(text);
  if ( check == true )
  {
    window.location.href = target;
  }
}


/**
 * Creates a styleable select-box
 *
 * [2007-08-14 as] created
 *
 * @since 0.1
 */
function classDropDown(sid, dd) {

   var sid = sid;
   var self = this;
   var selectValues = new Array();
   this.dl;

   this.drop = function() {

   	  var ret = "none";
      this.dl = document.getElementById(sid);

      if(this.dl.style.display == "none") {

      	 ret = "block";
      	 this.list();
      }

      this.dl.style.display = ret;
   }

   this.hide = function () {

      if (this.dl) {
          if (this.dl.style.display == "block") this.dl.style.display = "none";
      }
   }

   this.list = function() {

      var arg = dd.list.split(";");
      var table = document.getElementById("tab_"+sid);

      // delete all b4 call
      for(i=table.rows.length; i>0; i--) { table.deleteRow(i-1); }

      for(var x=0; x<arg.length; x++){

         var tr = table.insertRow(x);

         for(var y=0; y<1; y++){

            var zelle = document.createElement("td");
            var att = arg[x].split("::");

            // unique name, value
            zelle.id = "zelle_" + att[1] + "_" + x + y;

            // event definition
            zelle.onclick = function() { self.appendInput(this.id, this.title); };
            // for IE6 compatibility
            zelle.onmouseover = function() { self.hovera(this); }
            zelle.onmouseout =  function() { self.hoverb(this); }

            selectValues[att[1]] = att[0];

            var inhalt = document.createTextNode(att[0]);
            zelle.appendChild(inhalt);
            tr.appendChild(zelle);
         }
      }

      //alert(document.getElementById(sid).innerHTML);

   }

   this.hovera = function(i) {

   		i.style.background = dd.hover || "#ebdac1";
      i.style.cursor = "pointer";
   }

   this.hoverb = function(i) {

      i.style.background = "transparent";
   }

   this.appendInput = function(id, title) {

      var input = document.getElementById("input_" + sid);
      var option = document.getElementById("attrib_" + sid);

      input.value = document.getElementById(id).innerHTML;

      var wert = id.split("_");
      option.value = wert[1];

      document.getElementById(sid).style.display = "none";

      if(dd.click) {
      	dd.click();
      }
   }
}

/**
 * function mouse x/y
 *
 * [2007-08-14 js] created
 *
 * @since 0.1
 */
var mouse = (function() {

	var posx = 0,
	    posy = 0;

	return {

		getcoords: function(ereignis) {

		 	// get normal coordinates (posx/posy)
	  	posx = document.all ? event.clientX : ereignis.pageX;
    	posy = document.all ? event.clientY : ereignis.pageY;

    	// calculate scroll only in IE necessary
    	if (document.all) {

	    	posx = parseInt(posx + $(document).scrollLeft());
	    	posy = parseInt(posy + $(document).scrollTop());
    	}
		},
  	getx: function() { return posx; },
  	gety: function() { return posy; }
	}
})();

// only when DOM loaded
$(document).ready(function() {

	document.onmousemove = mouse.getcoords;

	// to avoid conflicts in ad-gallery
	$("img[src$='.png']").css({
		behavior: 'url("/_lib/png/behavior.htc")'
	});
});

/**
 * Global Ajax Listener + Loading bar
 *
 * [2007-08-14 js] created
 *
 * @since 0.1
 */
var Loader = (function() {

	return {
		deactivate: false,
		init: function() {

			if (!this.deactivate) {
				$("#ajax_search_wait").show();
			}
		},
		close: function() {

			$("#ajax_search_wait").hide();
		}
	}
})();

// skips the "first load". only true reloads should have a loader.
$(window).load(function() {

	// Global Ajax Listener
	$(document).bind("ajaxStart", function(e) {
		Loader.init();
	});
	$(document).bind("ajaxSuccess", function(e) {
		Loader.close();
	});
});