/* NCC site tools (contact panel & search panel)
 * Dependencies: jQuery 1.2.1
 * @author : Isotop AB
 */ 
 
 function SiteTools()  {
 	this.panel = null;
	this.cPanel = null;
	this.sPanel = null;
	
	this.contactBtn = null;
	this.searchBtn = null;
	this.imgPath = "/media/img/txt/";

	this.init = function() {
	    var parent = this;
	    this.panel = $('#site-tools');
	    this.cPanel = $('#contact-panel');
	    this.sPanel = $('#search-panel');
	    this.otherContatcsPanel = $('#contact-panel .other-contacts');
	    this.searchPanel = $('#contact-panel .contact-search');

	    this.speed = '100';

	    this.searchField = $('#search-panel .search-field');

	    this.cPanelIsActive = false;
	    this.sPanelIsActive = false;

	    this.contactBtnLink = $('.contact-btn');
	    this.contactBtn = $('.contact-btn img');

	    this.searchBtn = $('.search-btn img');
	    this.searchBtnLink = $('.search-btn');

	    this.contactBtnLink.click(function() { parent.toggleCPanel(); });
	    this.searchBtnLink.click(function() { parent.toggleSPanel(); });

	    this.otherContactsLink = $('#contact-panel .footer-link a');

	    this.otherContactsLink.click(function() { parent.toggleOtherContacts(); });

	    this.closeBtn = $('#site-tools .close img');

	    this.closeBtn.click(function() {
	        (parent.cPanelIsActive) ? parent.toggleCPanel() : parent.toggleSPanel();
	    });

	    this.toggleCPanel = function() {
	        if (this.sPanelIsActive) {
	            this.toggleSPanel();
	            setTimeout("siteTools.toggleCPanel()", 500);
	            return;
	        }

	        parent.sPanel.css("display", "none");
	        parent.cPanel.css("display", "block");

	        if ((parent.panel.css("display") == 'none')) {
	            parent.contactBtn.attr("src", this.imgPath + page.languageBranch + "/btn_contact_active.gif");
	            parent.searchBtn.attr("src", this.imgPath + page.languageBranch + "/btn_search_inactive.gif");
	            this.cPanelIsActive = true;
	            this.searchPanel.show();
	            this.otherContatcsPanel.hide();
	            $('div.customerServiceRight').hide();

	        }
	        else {

	            parent.contactBtn.attr("src", this.imgPath + page.languageBranch + "/btn_contact_normal.gif");
	            parent.searchBtn.attr("src", this.imgPath + page.languageBranch + "/btn_search_normal.gif");
	            this.cPanelIsActive = false;
	            this.searchPanel.hide();
	        }

	        (parent.panel.css("display") == 'none') ? parent.panel.slideDown(parent.speed) : parent.panel.slideUp(parent.speed);
	    }

	    this.toggleSPanel = function() {
	        //alert(parent.cPanel.css("display"));
	        if (this.cPanelIsActive) {
	            this.toggleCPanel();
	            setTimeout("siteTools.toggleSPanel()", 500);
	            return;
	        }


	        parent.cPanel.css("display", "none");
	        parent.sPanel.css("display", "block");

	        if ((parent.panel.css("display") == 'none')) {
	            parent.contactBtn.attr("src", this.imgPath + page.languageBranch + "/btn_contact_inactive.gif");
	            parent.searchBtn.attr("src", this.imgPath + page.languageBranch + "/btn_search_active.gif");
	            this.sPanelIsActive = true;

	        }
	        else {

	            parent.contactBtn.attr("src", this.imgPath + page.languageBranch + "/btn_contact_normal.gif");
	            parent.searchBtn.attr("src", this.imgPath + page.languageBranch + "/btn_search_normal.gif");
	            this.sPanelIsActive = false;
	        }

	        (parent.panel.css("display") == 'none') ? parent.panel.slideDown(parent.speed) : parent.panel.slideUp(parent.speed);
	        setTimeout("siteTools.searchField.focus()", 250);


	    }

	    this.toggleOtherContacts = function() {
	        this.otherContatcsPanel.toggle();
	        this.searchPanel.toggle();
	        $('div.customerServiceRight').toggle();
	    }


	}
 }

 function goToContacts(url) {
         if (url == '') {
             var a = $('#' + $('#regionValue').children().val()).val();
            location.href = a;
         }
    
        else {       if ($('#citySelect').attr('class').indexOf('disabled') == -1)
             location.href = url;
           else
               $('#nonevalidmsg').show();
    }
 }

 function refreshContacts(url) {
     if (url == '') {
         var a = $('#' + $('#firstFilterValueContainer').children().val()).val();
         location.href = a;
     }

     else {
             location.href = url;
     }
 }
 
 var siteTools = new SiteTools();