var URL = '/';

function goGet(param, id) {
	advAJAX.get({
	    url: URL+param,
	    onSuccess : function(obj) { document.getElementById(id).innerHTML = obj.responseText; }
	});
}

function $(el){
return typeof(el) == 'string' ? document.getElementById(el) : el;
}
function getChildren(el, a, v) {
	var ar = new Array();
	var ac = $(el).getElementsByTagName('*');
	var s = '';
	for (c=0; c<ac.length; c++){
	  if (v? (ac[c][a] == v || ac[c].getAttribute(a) == v) : (ac[c][a] || ac[c].getAttribute(a))) {
		ar.push(ac[c]);
	  }
	}
	return ar;
}
function d(){
   console.debug(arguments);
}

function addEvent(obj, type, fn) {
  if (obj.addEventListener) {
    obj.addEventListener(type, fn, false);
  } else if (obj.attachEvent) {
    obj["e"+type+fn] = fn;
    obj[type+fn] = function() {obj["e"+type+fn](window.event); }
    obj.attachEvent("on"+type, obj[type+fn]);
  }
}
function eventHander(e) {
   var el;
   if(window.event && window.event.srcElement) el = window.event.srcElement;
   if(e && e.target) el = e.target;
   if(!el)  return;
   (e.preventDefault) ? e.preventDefault() : (e.returnValue = false);
   return el;
}
function isDef(el) {
  return (el != "undefined" && el != null)
}
function cDOM(name, attrs) {
  var i = 1;
  var el = document.createElement(name);

  if(isDef(attrs[0]) && typeof(attrs[0]) != "string") {
    for(k in attrs[0]) {
      if(k == "style")
        el.style.cssText = attrs[0][k];
      else if(k == "class")
        el.className = attrs[0][k];
      else if(k == 'inner')
         el.innerHTML = attrs[0][k];
      else
        el.setAttribute(k, attrs[0][k]);
    }
    for(i; i < attrs.length; i++) {
      var n = attrs[i];
      if(isDef(n)) {
        if(typeof(n) == "string")
          n = document.createTextNode(n);
        el.appendChild(n);
      }
    }
  } else {
    var n = attrs[0];
    if(isDef(n)) {
      n = document.createTextNode(n);
      el.appendChild(n);
    }
  }
  return el;
}
var DIV = function(){return cDOM.apply(this,['DIV',arguments]);};
var IMG = function(){return cDOM.apply(this,['IMG',arguments]);};
var INPUT = function(){return cDOM.apply(this,['INPUT',arguments]);};
var A = function(){return cDOM.apply(this,['A',arguments]);};
var P = function(){return cDOM.apply(this,['P',arguments]);};
var SPAN = function(){return cDOM.apply(this,['SPAN',arguments]);};
var LABEL = function(){return cDOM.apply(this,['LABEL',arguments]);};
var SELECT = function(){return cDOM.apply(this,['SELECT',arguments]);};
var B = function(){return cDOM.apply(this,['B',arguments]);};


Function.prototype.bind = function(obj){
   var fn = this, args = [];

   for (var i = 0; i < arguments.length-1; i++) args[i] = arguments[i+1];
   return function(){
      return fn.apply(obj, args);
   };
}
Function.prototype.bindAsEventListener = function(obj){
   var fn = this, args = [];
   for (var i = 0; i < arguments.length-1; i++) args[i] = arguments[i+1];
   return function(event){
      return fn.apply(obj, [event||window.event].concat(args));
   };
}
Object.extend = function(dest, source) {
  for (var i in source) {
    dest[i] = source[i];
  }
  return dest;
}


MK = {};
MK.shell ={
   point : function(x,y){
      return {x:x,y:y};
   },
   scrollOffset : function(){
      
      var x = 0;
      var y = 0;
      if( typeof( window.pageYOffset ) == 'number' ) {
         y = window.pageYOffset;
         x = window.pageXOffset;
      }else
         if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
            y= document.body.scrollTop;
            x= document.body.scrollLeft;
         }else
            if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
             //IE6
             y = document.documentElement.scrollTop;
             x= document.documentElement.scrollLeft;
         }
      return this.point(x,y);
   },

   screenSize : function() {
      var x = 0;
      var y = 0;
      if (window.innerHeight >= 0) {
         x = window.innerWidth;
         y = window.innerHeight;
      } else if (document.documentElement) {
         x = document.documentElement.clientWidth;
         y = document.documentElement.clientHeight;
      } else if (document.body.clientHeight >= 0) {
         x = document.body.clientWidth;
         y = document.body.clientHeight;
      }
      return this.point(x,y);
   },
   pageSize : function() {
      var x = 0;
      var y = 0;
      var test1 = document.body.scrollHeight;
      var test2 = document.body.offsetHeight
      var test3 = document.documentElement.offsetHeight;
      var y = test1;
      if(y < test2){
         y = test2;
      }
      if(y < test3){
         y = test3;
      }
      if (test1 > test2) {
         // all but Explorer Mac
         x = document.body.scrollWidth;
      }
      else{
         // Explorer Mac;
         //would also work in Explorer 6 Strict, Mozilla and Safari
         x = document.body.offsetWidth;
      }
      return this.point(x,y);
   }
}

MK.Mask = {
   show: function(){
      inputSelect(false);
      var mask = $('pageMask');
      mask.style.display = 'block';
      var ua = navigator.userAgent;
      var f = "MSIE 6";
      if ((i = ua.indexOf(f)) >= 0) {
         mask.style.top = $('container').offsetTop;
         mask.style.marginLeft = $('container').offsetLeft;
         mask.style.width = $('container').offsetWidth;
         mask.style.height = $('container').offsetHeight;
      }
   },
   hide: function(){
      $('pageMask').style.display = 'none';
      inputSelect(true);
   }
};



MK.anim = {
   obj:null,
   name:null,
   y:0,
   max:0,
   time:1,
   step:20,
   dir:0,
   cont:null,
   isInit:false,
   isOpen:false,
   change:function(obj,max){
      this.init(obj,max);
      if(this.isOpen){
         this.close();
      }else{
         this.open();
      }
      this.isOpen = !this.isOpen;
   },
   open:function(){
      this.dir = 1;
      this.move();
   },
   close:function(){
      this.dir = -1;
      this.move();
   },
   init:function(obj,hmax){
      this.max = hmax;
      
      if(obj != this.cont){
         
         this.cont = obj;
         this.gallery = getChildren(this.cont,'className','galleryCont')[0];

         if(this.gallery.style.display == 'none' || this.cont.style.display == ''){
            this.cont.style.height = '0';
            this.cont.style.display = 'block';
            this.isOpen = false;
            this.y = 0;
         }else{
            this.y = this.cont.offsetHeight;
            this.isOpen = true;
         }
         
      }
      this.gallery.style.display = 'none';
//      this.cont.parentNode.insertBefore(this.obj,this.cont);
//      this.obj.appendChild(this.cont);
   },
   move:function(){
      if((this.dir > 0 && this.cont.offsetHeight < this.max)  || (this.dir < 0 && this.cont.offsetHeight > 0)){
         this.y+=this.step * this.dir;
         this.cont.style.height=this.y+'px';
         setTimeout("MK.anim.move();",this.time);
      }else{
         if(this.dir == 1){
            this.gallery.style.display = 'block';
         }
         this.dir = 0;
      }
      
   }
};
function collectionGallery(){
   var hands = getChildren(document,'className','galleryHand');
   var cont = getChildren(document,'className','galleryHide');
   for(var i = 0;i< cont.length;i++){
      if(hands[i] != undefined && cont[i] != undefined){
         //addEvent(hands[i],'click',MK.anim.change.bind(MK.anim,cont[i],365));
         hands[i].style.display = 'none';
         cont[i].style.display = 'block';
      }
   }
}


addEvent(window,'load',function(){
   collectionGallery();
});

