// Generated from /mobitec/proxy.phtml?showstub=true, DO NOT EDIT!
if(typeof(MobitecController) == 'undefined')
    MobitecController = new Object();

Object.extend(MobitecController,
{
    _callback4992a3959cc06: "/mobitec/proxy.phtml",

    _getJSON: function(r, j)
    {
        j = (j || r.headerJSON || r.responseJSON);
        if(j == null)
            return null;
        if(j.errors || j.failed)
        {
            var f = function(a, c)
            {
                var e = $(c);
                if(a.length > 0)
                {
                    var s = '<ul>';
                    $(a).each(function(e){ s += '<li>'+e+'</li>'; });
                    s += '</ul>';
                    if(e){ e.update(s); e.show(); }
                }
                else
                {
                    if(e){ e.hide(); }
                }
            }
            if(!j.errors)
            {
                j.errors = {error: [], warning: [], info: []}
                if(j.failed)
                    j.errors.error[0] = j.message;
            }

            f(j.errors.error, 'globuleError');
            f(j.errors.warning, 'globuleWarning');
            f(j.errors.info, 'globuleInfo');
        }
        return j;
    },

    _proxy: function(callbackurl, methodName, args, sync)
    {
        var targs = $H();
        for(var i = 0; i < args.length-1; i++){ targs.set('args[' + i + ']', args[i]); }
        callback = args[args.length-1];
        var ar = new Ajax.Request(callbackurl + '?method=' + methodName,
        {
            method: 'post',
            asynchronous: (!sync),
            parameters: targs,
            onComplete: (sync)?null:callback,
            onException: function(request, e){console.debug(request, e);}
        });
        if(sync)
            return new Ajax.Response(ar);
    },

    _getLineAndImages: function(){ this._proxy(this._callback4992a3959cc06, '_getLineAndImages', arguments, false); },
    _getLineAndImages_sync: function(){ return this._proxy(this._callback4992a3959cc06, '_getLineAndImages', arguments, true); },

    _getModelImages: function(){ this._proxy(this._callback4992a3959cc06, '_getModelImages', arguments, false); },
    _getModelImages_sync: function(){ return this._proxy(this._callback4992a3959cc06, '_getModelImages', arguments, true); },

    _t: ''
});


// Generated from /admin/mobitec/proxy.php, DO NOT EDIT!
if(typeof(MobitecController) == 'undefined')
    MobitecController = new Object();

Object.extend(MobitecController, {
   _lineImages: null,
   _inZoomMode:false,
   _inDragMode:false,
   _modelImages:null,
   _currentModelImage:null,
   _objDraggable:null,
   _line:null,
   _currentLine:null,
   _modelIPP:12,
   
   
   loadLineImages: function(line,page)
   {
   		this._getLineAndImages(line,page,this.lineImagesLoaded.bind(this));
   },
   lineImagesLoaded:function(i,j)
   {
   		j = this._getJSON(i, j);
        if(j && !j.failed)
        {
  			this._line=j.out;
  			this._currentLine=-1;
  			this.initLineView();
   	    }   
   },
   initLineView:function()
   {
   		
   		this.updateTitle(this._line.isoLineName);
   		var lineTplContener="<div class='zoom-tools'><a href='#' class='prev' onclick='MobitecController.prevLinePage();return false;'></a><span id='currentPage'></span><span id='totalPage'></span><a href='#' onclick='MobitecController.nextLinePage();return false;' class='next'></a></div>";
   		lineTplContener+="<div id='line-container' class='line-container' ></div>";
  		$('rightContent').update(lineTplContener);
  		
  		$('totalPage').update("/ "+(Math.ceil(this._line.models.length/this._modelIPP)).toString());
   		$('currentPage').update("1");
  		this.nextLinePage();
  		
   },
   nextLinePage:function()
   {
   		var numPage=this._currentLine+1;
   		if(numPage < Math.ceil((this._line.models.length/this._modelIPP)) )
   		{
   			if(!$('linePage'+numPage))
   			{
   				var limitMin=(numPage)*this._modelIPP;
   				var limitMax=limitMin+this._modelIPP;
   				var pageModel=this._line.models.slice(limitMin,limitMax);
   				var t = new Template("<span class='line-item' onclick='MobitecController.loadModel(\"#{reference}\");return false'><img src='/media/mobitec/model-overview/200/model-overview-#{imgUid}'  /><span class='line-item-title'>#{name}</span></span>");
  				var html='';
  				pageModel.each(function(e){
  					html+=t.evaluate(e);
  				});
  				$('line-container').update(html);
  				
   			}
   			else
   			{
				if($('linePage'+this._currentLine))
				{
					$(''+this._currentLine).hide();
				}				
   				$('linePage'+numPage).show();
   			}
   			$('currentPage').update(numPage+1);
   			this._currentLine++;
   			
   		}
   },
   prevLinePage:function()
   {
   		var numPage=this._currentLine-1;
   		if(numPage >=0)
   		{
   			if($('linePage'+numPage))
   			{
   				if($('linePage'+this._currentLine))
				{
					$(''+this._currentLine).hide();
				}				
   				$('linePage'+numPage).show();
   			}
   			else //:s
   			{
   				var limitMin=(numPage)*this._modelIPP;
   				var limitMax=limitMin+this._modelIPP;
   				var pageModel=this._line.models.slice(limitMin,limitMax);
   				var t = new Template("<span class='line-item' onclick='MobitecController.loadModel(\"#{reference}\");return false'><img src='/media/mobitec/model-overview/200/model-overview-#{imgUid}'  /><span class='line-item-title'>#{name}</span></span>");
  				var html='';
  				pageModel.each(function(e){
  					html+=t.evaluate(e);
  				});
  				$('line-container').update(html);
   			}
   			$('currentPage').update(numPage+1);
   			this._currentLine--;
   			
   		}
   },
   loadModel:function(modelId)
   {
   		
   		this._getModelImages(modelId,this.modelLoaded.bind(this));
   		
   },
   modelLoaded:function(i,j)
   {
   		j = this._getJSON(i, j);
        if(j && !j.failed)
        {
  			this._modelImages=j.out;
  			this.initModelView();
  			
  		}	
  			
   },
   initModelView:function()
   {
   		this.showLoader();
   		this._currentModelImage=0;
   		var imgName=this._modelImages.imgUid[this._currentModelImage];
   		var html="<div class='zoom-tools'><a href='#' onclick='MobitecController.prevModel();return false;' class='prev'></a><span id='currentPage'></span><span id='totalPage'></span><a href='#' onclick='MobitecController.nextModel();return false;' class='next'></a></div>";
   		html+="<div id='zoom-container' class='zoom-container'>";
  		
  		this.updateTitle(this._modelImages.name);
  		//$('rightContentTitle').innerHTML=this._modelImages.name;
  		
  		html+="<img src='' id='imgZoomOutContainer'   />";
  		html+="<img style='display:none' src='/media/mobitec/model-overview/"+imgName.hd+"' id='imgZoomInContainer'   />";
  		
  		html+="</div>";
  		$('rightContent').update(html);
  		$('zoom-container').observe('mouseup',this.imgClickEvent.bindAsEventListener(this));
  		$('zoom-container').addClassName("zoom-magnifier");
  		$('totalPage').update("/ "+this._modelImages.imgUid.length.toString());
   		$('currentPage').update(1);
   		
   		this.preload_img = document.createElement('img');
   		$(this.preload_img).observe('load',this.centerZoomOutImage.bind(this));
   		this.preload_img.src = '/media/mobitec/model-overview/'+imgName.md;
   	},
   
   prevModel:function()
   {
   		var numModel=this._currentModelImage-1;
   		if(numModel >=0)
   		{
   			this._currentModelImage--;
   			this._zoomOut();
   			var imgName=this._modelImages.imgUid[this._currentModelImage];
   			this.showLoader();
   			
   			this.preload_img = document.createElement('img');
   			$(this.preload_img).observe('load',this.centerZoomOutImage.bind(this));
   			this.preload_img.src = '/media/mobitec/model-overview/'+imgName.md;
   			$('imgZoomInContainer').src='/media/mobitec/model-overview/'+imgName.hd;
   			$('currentPage').update(this._currentModelImage+1);
   			
   		}
   			
   },
   showLoader:function()
   {
   		$('rightContent').hide();
   		$('loader').show();
   },
   hideLoader:function()
   {
   		$('loader').hide();
   		$('rightContent').show();
   		
   },
   nextModel:function()
   {
   		var numModel=this._currentModelImage+1;
   		if(numModel < this._modelImages.imgUid.length)
   		{
   			this._currentModelImage++;
   			this._zoomOut();
   			var imgName=this._modelImages.imgUid[this._currentModelImage];
   			
   			
   			this.showLoader();
   			
   			this.preload_img = document.createElement('img');
   			$(this.preload_img).observe('load',this.centerZoomOutImage.bind(this));
   			this.preload_img.src = '/media/mobitec/model-overview/'+imgName.md;
   			$('imgZoomInContainer').src='/media/mobitec/model-overview/'+imgName.hd;
   			$('currentPage').update(this._currentModelImage+1);
   			$('zoom-container').removeClassName("zoom-hand-open");
   			$('zoom-container').removeClassName("zoom-hand-close");
   			$('zoom-container').addClassName("zoom-magnifier");
   			
   		}
   },
   centerZoomOutImage:function(e)
   {
   		$('imgZoomOutContainer').style.paddingLeft='0px';
   		$('imgZoomOutContainer').style.paddingTop='0px';
   		
   		
   		$('imgZoomOutContainer').src=this.preload_img.src;
   		
   		if(this.preload_img.width < 475)
   		{
   			var temp = (475 - this.preload_img.width) /2 ;
   			$('imgZoomOutContainer').style.paddingLeft=temp+'px';
   		}
   		if(this.preload_img.height < 410)
   		{
   			var temp = (410 - this.preload_img.height ) /2 ;
   			$('imgZoomOutContainer').style.paddingTop=temp+'px';
   		}
   		this.hideLoader();
   		
   },
   imgClickEvent:function(e)
   {
   		
   		if(this._inZoomMode)
   		{
   			if(!this._inDragMode)
   			{
  				
  				this._zoomOut();
  				$('zoom-container').removeClassName("zoom-hand-open");
   				$('zoom-container').removeClassName("zoom-hand-close");
   				$('zoom-container').addClassName("zoom-magnifier");
   			}
   			
   		}
   		else
   		{
   			var offset = $('imgZoomOutContainer').cumulativeOffset(); 
   			var ratio=$('imgZoomInContainer').width/$('imgZoomOutContainer').width;
   			var zoomInX=-((e.clientX-offset.left)*ratio-($('zoom-container').clientWidth/2));
   			var zoomInY=-((e.clientY-offset.top)*ratio-($('zoom-container').clientHeight/2));
   			
   			var minX=$('zoom-container').clientWidth - $('imgZoomInContainer').width;
  			var minY=$('zoom-container').clientHeight -$('imgZoomInContainer').height;
  			
  			zoomInX= (zoomInX < 0) ? (zoomInX > minX ? zoomInX : minX ): 0;
  			zoomInY= (zoomInY < 0) ? (zoomInY > minY ? zoomInY : minY ): 0;
   			this._zoomIn(zoomInX,zoomInY);
   			
   			$('zoom-container').addClassName("zoom-hand-open");
   			$('zoom-container').removeClassName("zoom-hand-close");
   			$('zoom-container').removeClassName("zoom-magnifier");
   			
   		}
   		
   },
   _zoomIn:function(x,y)
   {
   		this._makeDragable();
  		this._inZoomMode=true;
  		
  		$('imgZoomInContainer').style.top=y+"px";
   		$('imgZoomInContainer').style.left=x+"px";
   		$('imgZoomOutContainer').hide();
   		$('imgZoomInContainer').show();
   		
   },
   _zoomOut:function(e)
   {
 
   		this._inZoomMode=false;
   		if(this._objDraggable)
   		{
   			this._objDraggable.destroy();
   		}
   		$('imgZoomOutContainer').show();
   		$('imgZoomInContainer').hide();
   		
   	},   
   _makeDragable:function()
   {
   		
   		this._objDraggable=new Draggable('imgZoomInContainer',
   		{
  			snap: 
  				function(x, y,draggable)
  				{
  					var minX=draggable.element.parentNode.clientWidth - draggable.element.clientWidth;
  					var minY=draggable.element.parentNode.clientHeight - draggable.element.clientHeight
  					
  					return[(x < 0) ? (x > minX ? x : minX ) : 0,(y < 0) ? (y > minY ? y : minY) : 0 ];
  				},
  			onStart:
  				
  				function(draggable,e)
  				{
  					$('zoom-container').removeClassName("zoom-hand-open");
   					$('zoom-container').removeClassName("zoom-magnifier");
   					$('zoom-container').addClassName("zoom-hand-close");
  					this.initDelta=draggable.delta;
  					Event.stop(e);
  				}.bind(this),
  			onDrag: 
  				function(draggable, e)
  				{
        			var tmp=[e.target.offsetLeft,e.target.offsetTop]
        			if(this.initDelta[0] != tmp[0] || this.initDelta[1] != tmp[1])
        			{
        				
        				this._inDragMode=true;
        				
        			}
        			Event.stop(e);
        		}.bind(this) ,
    		onEnd: 
  				function(draggable, e)
  				{
        			this._inDragMode=false;
        			$('zoom-container').addClassName("zoom-hand-open");
   					$('zoom-container').removeClassName("zoom-hand-close");
   					$('zoom-container').removeClassName("zoom-magnifier");
        			Event.stop(e);
        		}.bind(this)
        		,starteffect : null, endeffect:null,ghosting:true
    	});
    	
  	},
  	updateTitle:function(title)
  	{
  		$('rightContentTitle').update(title);
  		if($('rightContentTitle').hasClassName('flir-replaced'))
  			$('rightContentTitle').removeClassName('flir-replaced');
  		$('rightContentTitle').flirReplaced=false;
   		FLIR.replace($('rightContentTitle'));
  	},
	initPictures:function(pictures)
    {
        this._pictures = pictures;
        $('next-picture').observe('click', this._nextPicture.bind(this));
        $('previous-picture').observe('click', this._previousPicture.bind(this));
        this._pictureIndex = 0;
        if(pictures.length > 1)
            $('next-picture').setStyle({visibility: ''});
	},    
    _nextPicture: function()
    {
        $('submodel-picture-img').src = this._pictures[++this._pictureIndex].thumb;
        $('previous-picture').setStyle({visibility: ''});
        if(this._pictureIndex == this._pictures.length-1)
            $('next-picture').setStyle({visibility: 'hidden'});
		$('donwload-picture-hr').href = this._pictures[this._pictureIndex].hr;
		if ( this._pictures[this._pictureIndex].hr != '' )
            $('donwload-picture-hr').setStyle({visibility: ''});
		else
            $('donwload-picture-hr').setStyle({visibility: 'hidden'});
    },
    
    _previousPicture: function()
    {
        $('submodel-picture-img').src = this._pictures[--this._pictureIndex].thumb;
        $('next-picture').setStyle({visibility: ''});
        if(this._pictureIndex == 0)
            $('previous-picture').setStyle({visibility: 'hidden'});
		$('donwload-picture-hr').href = this._pictures[this._pictureIndex].hr;
		if ( this._pictures[this._pictureIndex].hr != '' )
            $('donwload-picture-hr').setStyle({visibility: ''});
		else
            $('donwload-picture-hr').setStyle({visibility: 'hidden'});
		
    }
});
function toogleMenu(model)
{
	var elm=$(model);
	$$('.product-submenu-item').each(function(e){if(e != elm) e.hide();});	
	elm.toggle();
}
