if(typeof ArtsOnIT== 'undefined') {
    var ArtsOnIT=  {};
}

ArtsOnIT.NextPrev = Class.create();
ArtsOnIT.NextPrev.prototype = {

	initialize: function(url, product_id, prev_placeholder, next_placeholder, up_placeholder, slider_placeholder, slider_num_elm)
	{
		  hash = window.location.hash;
		  this.onGetData = this.getData.bindAsEventListener(this);

		  if(hash.match('#NP='))
		  {
				hash = hash.replace('#NP=','');
				this.prev_elm = $(prev_placeholder);				
				this.next_elm = $(next_placeholder);	
				this.up_elm = $(up_placeholder);	
				this.slider_elm = $(slider_placeholder);	

				this.req_prev  = 0;
				this.req_next  = 0;
				this.req_slider= 0;
				this.req_up= 0;
				if (this.prev_elm)	this.req_prev 	= 1;	
				if (this.next_elm)	this.req_next 	= 1;
				if (this.up_elm)	this.req_up 	= 1;
				if (this.slider_elm)	this.req_slider 	= 1;

				
				var request = new Ajax.Request(
                url,
                {
						method: 'get', onFailure: this.ajaxFailure.bind(this),  onSuccess: this.onGetData,
						parameters: {
							hash: hash, 
							product_id: product_id, 
							withprev: this.req_prev, 
							withnext: this.req_next,
							withslider: this.req_slider,
							withup: this.req_up,
							slider_num_elm : slider_num_elm
						 }
					}
					
            );
			try
			{
				document.addEventListener('keydown', this.keypress.bind(this) , false);
			}
			catch(ex)
			{
			}
		  }
	},
	ajaxFailure: function(){
		if (this.prev_elm)
		{
			this.prev_elm.hide();
		}
		if (this.next_elm)
		{
			this.next_elm.hide();
		}
		if (this.slider_elm)
		{
			this.slider_elm.hide();
		}
		if (this.slider_up)
		{
			this.up_elm.hide();
		}
	},
	addInfoUrl: function(url){
		
		alert(window.location);
	},
	addInfoSetLocation: function(url){
		url = this.addInfoUrl(url);
	   return url;
	},
	getData: function(transport){
        if (transport && transport.responseText){
            try{
                response = eval('(' + transport.responseText + ')');
            }
            catch (e) {
                response = {};
            }
        }

        if (response.error) {
            this.ajaxFailure();
            return false;
        }

        if (response.next) {
            this.next_elm.update(response.next);
            response.next.evalScripts();
        }

        if (response.prev) {
            this.prev_elm.update(response.prev);
            response.prev.evalScripts();
        }
 
		if (response.slide) {
            this.slider_elm.update(response.slide);
            response.slide.evalScripts();
        }
		if (response.up) {
            this.up_elm.update(response.up);
            response.up.evalScripts();
        }
    },
	keypress: function(event)
	{
		if (window.event) event = window.event;
		key = event.keyCode ? event.keyCode : event.which ? event.which : null;
		elm = null;
		switch (key )
		{
			case 37: elm = this.prev_elm;
			 break;
 			case 39: elm = this.next_elm;
			 break;
			case 38: elm = this.up_elm;
			 break;
		}
		if (elm)
		{
			href = elm.down('a').href;
			if (href)
			{
				document.location = href;
			}
		}
	}
}
