/*
* 2011 POOEL PROJECTS - Pooel-WA 
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to info@pooel.it so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Pooel-WA to newer
* versions in the future. If you wish to customize Pooel-WA for your
* needs please refer to http://www.pooel.it for more information.
*
*  @author Pooel <info@pooel.it>
*  @copyright  2007-2011 Pooel
*  @version  Release: 1.0
*  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*/
// JS General

var POO;
function PooelJSEffects(type,property){
    this.type = type;
    this.property = property;
}

var t = PooelJSEffects.prototype;
    t.loop = null;
    t.obj = null;
    t.timer = null;
    t.list = null;
    t.listX = null;
    t.listY = null;
    t.listNav = null;
    t.width = null;
    t.height = null;
    t.current = null;
    t.animation = null;
    
    t.initialize = function(){
        if(document.getElementById(this.property.obj)){
            this.obj = document.getElementById(this.property.obj);
            this.listNav = document.getElementById(this.property.objnav);
            this.setWidth();
            this.setHeight();
            this.setCurrent(0);
            this.setTimer(this.property.timer);
            this.loop = true;
            this.resetSquare();
            this.startAnimation();

        }
    }
    
    t.setNodes = function(_obj){
        this.list = document.getElementById(_obj).childNodes;
    }
    
    t.setNodesNav = function(_obj){
        this.listNav = document.getElementById(_obj).childNodes;
    }
    
    t.setWidth = function(){
        this.width = this.obj.childNodes[0].offsetWidth;
        this.obj.style.width = this.width*this.obj.childNodes.length + 'px';
        this.obj.style.position = 'relative';
        this.obj.style.left = 0+'px';
        
    }
    
    t.setHeight = function(){
        this.height = this.obj.childNodes[0].offsetHeight;
    }
    
    t.setCurrent = function(_obj){
        this.current = _obj;
    }
    
    t.setTimer = function(time){
        this.timer = time;
    }
    
    t.resetSquare = function(){
        if(this.listNav!=null)
        for(i=0;i<this.listNav.childNodes.length;i++){
            this.listNav.childNodes[i].style.background = '#999';
        }
        this.listNav.childNodes[this.current].style.background = '#662D91';
    }
    
    t.setAnimation = function(){
        this.animation = null;
        var o = this.width*this.current;
        var d = this.width*(this.current+1);
        
        this.setCurrent(this.current+1);
        if(this.current==this.obj.childNodes.length){this.setCurrent(0); d=0;}
        this.resetSquare();
        this.animation = new Tween(this.obj.style,'left',Tween.regularEaseOut, -o, -d, 0.3,'px');
        this.animation.start();
        this.startAnimation();
    }
    
    t.startAnimation = function(){
        if(this.loop!=null){
            this.loop = setTimeout("POO.setAnimation()",this.timer);
        }
    }
    
function PooelJSPhoto(type,property){
    this.type = type;
    this.property = property;
}

var p = PooelJSPhoto.prototype;
    p.bg = null;
    p.box = null;
    p.mother = null;
    p.idcurrent = null;
    p.current = null;
    p.width = null;
    p.height = null;
    p.prefurl = '';
    p.sufurl = '';
    
    p.setPhotoCont = function(pref,id){
        var objCall = document.getElementById(pref+id);
        this.current = parseInt(id);
        this.idcurrent = pref;
        valueObjCall = objCall.title.split('|');
        var tit = valueObjCall[0] ? valueObjCall[0]:'notitle';
        var url = valueObjCall[1] ? valueObjCall[1]:'nourl';
        var newdiv = document.createElement("div");
        newdiv.setAttribute('class','bgPopUp');
        newdiv.setAttribute('id','bgPopUp');
        newdiv.setAttribute('onclick','POO.closePhoto(POO.property)');
        var newdivPhoto = document.createElement("div");
        newdivPhoto.setAttribute('class','boxPopUp');
        newdivPhoto.setAttribute('id','boxPopUp');
        newdivPhoto.style.opacity=0;
        this.mother = document.getElementById(this.property.mother);
        this.bg = newdiv;
        this.box = newdivPhoto;
        this.mother.appendChild(newdiv);
        this.mother.appendChild(newdivPhoto);
        var newimage = document.createElement("img");
        var file = ''+this.property.prefurl+url+this.property.sufurl+'';
        file = file.replace(/&amp;/gi,'&');
        newimage.src = file;
        newimage.setAttribute('onload','POO.alphaPhoto()');
        newdivPhoto.appendChild(newimage);
        newdivPhoto.innerHTML +='<div id="closeP" onclick="POO.closePhoto(POO.property)"><b>&#x2716;</b></div>';
        newdivPhoto.innerHTML +='<div id="titphotoP">'+tit+' #'+id+'</div>';
        if(this.property.control && this.property.control==true){
        newdivPhoto.innerHTML +='<div id="nextPhotoP" onclick="POO.nextPhoto()" class="btnPhoto">&#x25B6;</div>';
        newdivPhoto.innerHTML +='<div id="prevPhotoP" onclick="POO.prevPhoto()" class="btnPhoto">&#x25C0;</div>';
        }
        this.openAnim();
    }
    p.nextPhoto = function(){
        this.current+=1;
        if(!document.getElementById(this.idcurrent+this.current))this.current=1;
        this.reloadPhoto();
    }
    p.prevPhoto = function(){
        this.current-=1;
        if(!document.getElementById(this.idcurrent+this.current))this.current=1;
        this.reloadPhoto();
    }
    p.reloadPhoto = function(){
        var newLi = document.getElementById(this.idcurrent+this.current);
        var boxIM = document.getElementById('boxPopUp').getElementsByTagName('img')[0];
        valueObjCall = newLi.title.split('|');
        var tit = valueObjCall[0] ? valueObjCall[0]:'notitle';
        var url = valueObjCall[1] ? valueObjCall[1]:'nourl';
        boxIM.style.opacity=0;
        var file = ''+this.property.prefurl+url+this.property.sufurl+'';
        file = file.replace(/&amp;/gi,'&');
        boxIM.src=file;
        document.getElementById('titphotoP').innerHTML = tit;
    }
    p.openPhoto = function(url,title){
        this.setPhotoCont(url,title);
        

    }
    p.alphaPhoto = function(){
        var ph = document.getElementById('boxPopUp').getElementsByTagName('img')[0];
        var alp = new OpacityTween(ph,Tween.regularEaseOut, 0, 100, 0.4);
        alp.start();
    }
    p.openAnim = function(){
        var alp = new OpacityTween(this.bg,Tween.regularEaseOut, 0, 80, 0.2);
        alp.onMotionFinished = function (){
            var twe = new OpacityTween(document.getElementById('boxPopUp'),Tween.regularEaseOut, 0, 100, 0.2);
            twe.start();
        }
        alp.start();
    }
    
    p.closePhoto = function(property){
        document.getElementById('bgPopUp').removeAttribute('onclick');
        /*var alp = new OpacityTween(document.getElementById('boxPopUp'),Tween.regularEaseOut, 80, 0, 0.2);
        if(alp){
        alp.onMotionFinished = function (){
            var twe = new OpacityTween(document.getElementById('bgPopUp'),Tween.regularEaseOut, 100, 0, 0.2);
            twe.onMotionFinished = function (){
                document.getElementById(property.mother).removeChild(document.getElementById(property.mother).lastChild);
                document.getElementById(property.mother).removeChild(document.getElementById(property.mother).lastChild);
            }
            twe.start();
        }
        alp.start();
        }else{*/
            document.getElementById(property.mother).removeChild(document.getElementById(property.mother).lastChild);
            document.getElementById(property.mother).removeChild(document.getElementById(property.mother).lastChild);
        //}
        
        
    }

function PooelJSMap(div) {
    //http://maps.google.it/maps?q=iron+g+roma&hl=it&sll=41.442726,12.392578&sspn=23.088186,46.010742&vpsrc=0&t=m&z=14
    var latlng = new google.maps.LatLng(41.908949,12.469256);
    var myOptions = {
      zoom: 12,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById(div),
        myOptions);

    var image = 'images/favicon.png';
    var myLatLng = new google.maps.LatLng(41.908949,12.469256);
    var beachMarker = new google.maps.Marker({
    position: myLatLng,
    map: map,
    icon: image
    }); 
}

function loadListProd(){
    var addFacebook = '';
    var link = 'other_modules/prestashop/newproduct.php';
    if(varJS['facebook'] && varJS['facebook']=='true')addFacebook='?facebook=true';
    textRequestPost(link+addFacebook,'code=8235ewhufihseufg3842','bodyListProd',null);
}
