/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function tresc(parentNode,dep){

    this.parentNode = parentNode;
    this.baseDiv = null;
    this.initadd = function(){

    };
    this.init = function(){
        this.baseDiv = this.baseDiv.appendChild(document.createElement('div'));
        this.baseDiv.setAttribute("id", "tresc");
        this.baseDiv.setAttribute("class", "html");
        this.baseDiv.style.overflow = "auto";

        this.initadd();
    };

    this.initWin = function(){
        this.win = new filip_owl({
            parentNode:this.parentNode,
            WinName:"Tresc",
            WindowId:"tresc",
            zIndex:1,
            move:1
        });
        this.initadd();
        this.baseDiv = this.win.WinMain;
    };
    this.get_links = function(){
        return this.baseDiv.getElementsByTagName("flink")
    };
    this.rm = function(){
        //  while(this.baseDiv.firstChild)
        this.baseDiv.parentNode.removeChild(this.baseDiv);
    };

    this.response = function(){
        this.owner.initadd();
        //        this.owner.responseCostom();
        //
        //              if(parseInt($.cookie('the_cookie'))>=91)
        //            $.cookie('the_cookie', '1');
        //        else
        //            $.cookie('the_cookie', 1+(parseInt($.cookie('the_cookie'))));
        //          $('html').css( 'background-image', "url('http://89.161.149.186/landscape/art/tapety/t"+$.cookie('the_cookie')+".jpg')");
        if(this.owner.oferta)
            this.owner.oferta.rm();
        this.owner.oferta = null;
        this.owner.win.WinName.innerHTML = this.getText(this.req.responseXML.getElementsByTagName("nazwa")[0]).replace(/;/, "").replace(/(_+\w+)/,"");
        //        var tmp ;
        //        $(tmp).html(this.getText(this.req.responseXML.getElementsByTagName("tresc")[0]));
       
        switch($(this.getFixXML()).find("special").text()){
            case  "Nowości":
                this.owner.baseDiv.innerHTML = '';
                this.owner.oferta = new news(this.owner.win);
                this.owner.oferta.init();
                break;
     
            case  "gallery":
                this.owner.win.load();
                if(!$(this.getFixXML()).find("popup").get(0))
                {
                    this.owner.baseDiv.innerHTML = '';
                    if(this.owner.baseDiv)
                        this.owner.ogallery =  new gallery({
                            win:this.owner.win,
                            baseDiv:this.owner.baseDiv,
                            galleryId:$(this.getFixXML()).find("special").attr("gid"),
                            style:$(this.getFixXML()).find("special").attr("style")
                        });
                
                }
                else
                {
                    this.owner.baseDiv.innerHTML = this.getText(this.req.responseXML.getElementsByTagName("tresc")[0]).replace(/<and>/g, "&");
                    $(this.owner.baseDiv).find("special").text("");
                    if(this.owner.baseDiv)
                        this.owner.ogallery =  new gallery({
                            win:this.owner.win,
                            baseDiv:$(this.owner.baseDiv).find("special").get(0),
                            galleryId:$(this.getFixXML()).find("special").attr("gid"),
                            style:$(this.getFixXML()).find("special").attr("style")
                        });
                }
                this.owner.ogallery.init();
                
                break;   
                
            case  "gallery_grid":
                if(this.owner.ogallery)this.owner.ogallery.hide();

                if(this.getText(this.req.responseXML.getElementsByTagName("tresc")[0]))
                    this.owner.baseDiv.innerHTML = this.getText(this.req.responseXML.getElementsByTagName("tresc")[0]).replace(/<and>/g, "&");
                else
                    this.owner.baseDiv.innerHTML = "";
                if(this.owner.baseDiv)
                    $(this.owner.baseDiv).find("gallery_grid").each(function(){
                        var tmp = new gallery_grid({
                            win:tresc.win,
                            baseDiv:$(this).get(0),
                            galleryId:$(this).attr("gid")
                        });
                        tmp.init();
                    })
                $(this.owner.baseDiv).find("special").text("");
              
                break;   
                
                
                
            //                javascript:$.ajax({
            //  url: "http://89.161.149.186/landscape/wyslij.php",
            //  context: document.body,
            //   data: $("form"),
            //  success: function(){
            //    alert("wysłano");
            //  }
            //});
                
                
                
                
                
                
                
                
                
            //            case  "map":
            //               
            //              // alert($base.find("special").attr("divId"));
            //                if(this.owner.ogallery)this.owner.ogallery.hide();
            //
            //                if(this.getText(this.req.responseXML.getElementsByTagName("tresc")[0]))
            //                    this.owner.baseDiv.innerHTML = this.getText(this.req.responseXML.getElementsByTagName("tresc")[0]).replace(/<and>/g, "&");
            //                else
            //                    this.owner.baseDiv.innerHTML = ""; 
            //                var $base = $(this.owner.baseDiv);
            //               
            //                var latlng = new google.maps.LatLng($base.find("special").attr("clat"), $base.find("special").attr("clng"));
            //                var myOptions = {
            //                    zoom: 8,
            //                    center: latlng,
            //                    mapTypeId: google.maps.MapTypeId.ROADMAP
            //                };
            //                var map = new google.maps.Map($base.find("#"+$base.find("special").attr("divId")).get(0),
            //                    myOptions);
            //               
            //               
            //            
            //
            //                break;  
            default:
                //  this.owner.init();
                

                if(this.getText(this.req.responseXML.getElementsByTagName("tresc")[0]))
                    this.owner.baseDiv.innerHTML = this.getText(this.req.responseXML.getElementsByTagName("tresc")[0]).replace(/<and>/g, "&");
                else
                    this.owner.baseDiv.innerHTML = ""; 
                
                $("form").submit(function () { 
                    
                    var post = "";
                    
                    post = post + "from=" + $(':input[name="from"]').val();
                    
                    post = post + "&email=" + $('form :input[name="email"]').val();
                    
                    post = post + "&phone=" + $('form :input[name="phone"]').val();
                    
                    post = post + "&comments=" + $('form textarea[name="comments"]').val();
                    post = post + "&lng=" + lng;
         
                    
                    
                    $.ajax({
                        url: "http://89.161.149.186/landscape/wyslij.php",
                        context: document.body,
                        data: post,
                        type: "POST",
                        success: function(){
                
                            if (lng == ".de") alert("Nachricht wurde gesendet - Wir werden uns so schnell wie möglich melden");
                            if (lng == ".pl") alert("Wiadomość została wysłana - odpiszemy najszybciej jak to możliwe")
                            if (lng == ".en") alert("The message was send - we will answer you as soon as possible");
                    
                    
                        }
                    });
                
                    if (lng == ".de") alert("Nachricht wurde gesendet - Wir werden uns so schnell wie möglich melden");
                    if (lng == ".pl") alert("Wiadomość została wysłana - odpiszemy najszybciej jak to możliwe")
                    if (lng == ".en") alert("The message was send - we will answer you as soon as possible");
                     
                }); 
        }    //alert(this.req.responseXML.getElementsByTagName("script")[1].textContent);
        if($(this.owner.baseDiv).find("popup").length)
        {
            $(this.owner.baseDiv).find("popup").hide();
        
            //  alert($(this.owner.baseDiv).find("a[popup=\""+$(this.owner.baseDiv).find("popup").attr("title")+"\"]").html())
            $(this.owner.baseDiv).find("a[popup=\""+$(this.owner.baseDiv).find("popup").attr("title")+"\"]").get(0).to = this;
            var win_width = $(this.owner.baseDiv).find("popup").attr("wwidth");
            if(!win_width) win_width = 692;
            //
         
     
        
            //$(this.owner.baseDiv).find("a[popup=\""+$(this.owner.baseDiv).find("popup").attr("title")+"\"]").get(0).dialogcontent = $(this.owner.baseDiv).find("popup").clone();
        
            //          aler( $(this.owner.baseDiv).find("a[popup=\""+$(this.owner.baseDiv).find("popup").attr("title")+"\"]"))
            //          $(this.owner.baseDiv).find("a[popup=\""+$(this.owner.baseDiv).find("popup").attr("title")+"\"]").button()
            $(this.owner.baseDiv).find("a[popup=\""+$(this.owner.baseDiv).find("popup").attr("title")+"\"]").
            click(function() {
                var $popup = $($(this).get(0).to.owner.baseDiv).find("popup").clone();
                $popup.appendTo($(this).get(0).to.owner.baseDiv);
                $popup.find("a").slimbox()
                $popup.dialog({
                    minWidth: win_width,
                    bgiframe: true

                });
           
            })
        }
         
        $(this.owner.baseDiv).find(".slimbox").slimbox();
        this.owner.menu.mk_link();
        this.owner.change_bg(this.owner.baseDiv.getElementsByTagName("bg")[0]);
    }
    this.change_bg = function(node){
        if(!this.currentbgClass){
            if(!node)
                this.currentbgClass = "none";
            else
                this.currentbgClass = node.getAttribute("class");

            $("html").addClass(this.currentbgClass);
        }
        
        if(!node){
            var newClass = "none"
        } 
        else
            var newClass = node.getAttribute("class");

        if(newClass != this.currentbgClass){
     
            $("html").removeClass(this.currentbgClass)
          
            $("html").addClass(newClass);
       
            this.currentbgClass = newClass;
        }
       
        
    }
    this.initWin();
    this.ajax = new filip_ajax(this, this.response, this.win.load, this.win,dep,"ajax");
    //    this.ajax.spytaj("viev=");
    this.getDiv = function(){
        return this.baseDiv;
    }
}
