﻿/*
 * @author Alex
 */
   var InterfaceObject = Class.create(); 
   InterfaceObject.prototype = { 
     initialize: function(config) { 
     this.config = config;
           this.variables = {'tours':$A()}; 
           this.__loadConfig(); 
           Event.observe(window, 'load', function() {cartGUI.windowOnLoad();});         
     }, 
      
     windowOnLoad: function(){ 
     this.__drawCart();
     }, 
      
     __saveConfig: function() { 
      
			Cookie.set('cart_vars', encodeURI(Object.toJSON(this.variables)));
      
      // TOURS
      
      
 			
		 document.getElementById('proposition').innerHTML = 'выбрано обьектов <span id="count_obj" style="font-size: 1.3em; font-weight: bold;"> ' + this.variables.tours.length +' </span>';
		 if(this.variables.tours.length==0) 
		 {
			//document.getElementById('recyclear').style = "height: 1px; visibility:hidden ";
			document.getElementById('recyclear').style.height = "1px";
			document.getElementById('recyclear').style.visibility = "hidden";
			if(document.getElementById('player') != null)
			{
				document.getElementById('start_page').style.height = "150px";
				document.getElementById('intro').style.visibility = "visible";
				document.getElementById('intro').style.height = "auto";
			}
			
		}
		 else  
		 {
			document.getElementById('recyclear').style.visibility = "visible";
			document.getElementById('recyclear').style.height = "auto";
		 }
		 
		 if(document.getElementById('player')==null)
		{
		  if(document.getElementById('recyclear').style.visibility == "visible")
			   document.getElementById('start_page').style.height = 470-(124+24*document.getElementById('count_obj').innerHTML)-85+"px";
		  else
			document.getElementById('start_page').style.height = "385px";  
		}
		if(document.getElementById('player')!=null && document.getElementById('recyclear').style.visibility == "visible")
		{
			document.getElementById('start_page').style.height = "1px";
			document.getElementById('intro').style.height = "1px";
			document.getElementById('intro').style.visibility = "hidden";
			
		}
		
		
		 
     }, 
   
     __loadConfig: function() { 
         cartConfig = Cookie.get('cart_vars');
		 if(cartConfig != null){ 
         cartConfig = decodeURI(cartConfig);
		 this.variables = cartConfig.evalJSON(); 
         } 
     },

     __drawCart: function() { 
      cartHolderDIV = $(this.config.target_div);
    if(cartHolderDIV != null){ 
      // clean cart holder
     cartHolderDIV.update('');

     // EMPTY
     if(this.variables.tours.length == 0 ){
      cartHolderDIV.update('<p>'+this.config.empty_text+'</p>');
      cartHolderDIV.appendChild(Builder.node('a',{'href':'#','onclick':'runOrder(); return false;'},this.config.label_order));
      return 0;       
     }
     total = 0;
     // TOURS
     if (this.variables.tours.length) {
       // add label tours 
       table = Builder.node('table', {
        id: 'cart_tours',
        cellpadding: '2',
        cellspacing: '0',
        border: '0',
		style: 'font-weight:bold'
       });
       tbody = Builder.node('tbody');
       table.appendChild(tbody);
       
       for (var i = 0; i < this.variables.tours.length; i++) {   
	            
        tr = Builder.node('tr', 
         [
          Builder.node('td', [            
		   Builder.node('input',{'type':'image','src':'/file/cros.gif','onclick':'cartGUI.delItem("tour", '+i+'); return false;'}),           
          ]),
          Builder.node('td', Builder.node('a',{'href':'/read/sent_item2/id/' + this.variables.tours[i].oid, 'title':this.variables.tours[i].name},this.variables.tours[i].name )), 
 
         ]);
        
        
        tbody.appendChild(tr);
		if(i!=this.variables.tours.length-1)
			tbody.appendChild(Builder.node('tr',[Builder.node('td',{'colspan':'3', 'style':'background-image:url(/file/dots.gif); background-repeat:repeat-x; width:250px'},'')]));
       };
	   
       cartHolderDIV.appendChild(table);
     }
          
      
     }
     },
    
     addItem: function(type, data) {    
	 
     this.variables.tours[this.variables.tours.length] = data;      
     this.__drawCart();
     this.__saveConfig();
	 
     },
     
    check: function() {
		 
		 var recyclear = document.getElementById('recyclear');
		 if(recyclear!=null)
		 {
		 if(this.variables.tours.length==0)
		 {
			recyclear.style.visibility = "hidden";
			recyclear.style.height = "1px";
		 }
		 else  
		 {		    
			recyclear.style.visibility = "visible";
			recyclear.style.height = "auto";
			document.getElementById('proposition').innerHTML = 'выбрано обьектов  <span id="count_obj" style="font-size:1.3em; font-weight:bold;">' + this.variables.tours.length +'</span>';
		 }
		 }
     },
     
     delItem: function(type, id) {      
     this.variables.tours.splice(id,1);      
     this.__drawCart();
     this.__saveConfig();
     }
	 
    
   };
 var cartGUI = new InterfaceObject({'target_div':'cartHolder', 'label_tours':'Выбраные объекты', 'empty_text':'In deze website staan onze aanbiedingen. Deze kunt u selecteren en naar ons versturen. Wij doen u dan een gepaste aanbieding.<br/>Ook kunt u direct een offerte aanvragen'});   




