var cttcIndustry = {

    library: new Object(),
    /*=================================================================================
    Holds instances of elements and properties throughout the application usage
    =================================================================================*/

    init: function() {
        /*=================================================================================
        Initiates the template and applies basic styles depending on client side settings
        and options.
        =================================================================================*/
		cttcIndustry.initialization.dbgIE6();
        cttcIndustry.initialization.stNvAc();
        cttcIndustry.initialization.gtAjax();
        cttcIndustry.initialization.rmDfLk();
        String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); }
        String.prototype.ltrim = function() { return this.replace(/^\s+/, ""); }
        String.prototype.rtrim = function() { return this.replace(/\s+$/, ""); }
    },

    initialization: {
        /*=================================================================================
        Contains initialization funtions, properties and objects.
        =================================================================================*/
        apBdCs: function() {
            /*-----------------------------------------------------------------------------
            Appends the body className if it needs to have an orange content section.
            -----------------------------------------------------------------------------*/
            if (cttcIndustry.isSection('Industry_Research')) document.body.className += (document.body.className != '' ? ' ' : '') + 'cttc__appendContent';
        },
        stNvAc: function() {
            /*-----------------------------------------------------------------------------
            sets the active state on navigation
            -----------------------------------------------------------------------------*/
			var id = '';
            var isIndustry = function(v) { var ind = (cttcIndustry.getSection()).toLowerCase(); var att = document.body.getAttribute('_parentname'); return ind == v.toLowerCase() || (att && att.toLowerCase() == v.toLowerCase()); }
            var isInPath = function(v) { return ((window.location.href).toLowerCase()).indexOf(v.toLowerCase()) > -1; }
            var path = (window.location.href).toLowerCase();
            if (isIndustry('industry_research') || isInPath('Industry/Research')) id = 'cttc__navFindResearch';
            else if (isIndustry('industry_assessment') || isInPath('Industry/Assessment')) id = 'cttc__navCalculateAssessment';
            else if (isIndustry('industry_travel_industry') || isInPath('Industry/TravelIndustry')) id = 'cttc__navTravelIndustry';
            else if (isIndustry('industry_press_room') || isInPath('Industry/PressRoom')) id = 'cttc__navPressRoom';
			else if (isIndustry('industry_about') || isInPath('Industry/About')) id = 'cttc__navAboutCTTC';
			else if (isIndustry('industry_publications') || isInPath('Industry/Publications')) id = 'cttc__navPublications';
            if (id != '' && document.getElementById(id)) document.getElementById(id).className += ' active';
        },
        rmDfLk: function() {
            /*-----------------------------------------------------------------------------
            Removes the default.htm instance to all the links
            -----------------------------------------------------------------------------*/
            var links = document.getElementsByTagName('a');
            for (var a = 0; a < links.length; a++) if (((links[a].href).toLowerCase()).indexOf('default.htm') > -1) {
                links[a].href = (links[a].href).replace('default.html', '');
                links[a].href = (links[a].href).replace('default.htm', '');
            }
        },
        gtAjax: function() {
            /*-----------------------------------------------------------------------------
            debugs and overrides some style issues with IE6
            -----------------------------------------------------------------------------*/
            if (cttcIndustry.getSection() == "Industry_Research") {
                var fileref = document.createElement("script");
                fileref.setAttribute("type", "text/javascript");
                fileref.setAttribute("src", "/b2b/research/widget.aspx");
                document.getElementsByTagName("head")[0].appendChild(fileref);
            } else {
                cttcIndustry.ajax('/_ccs/testContent/index.cfm?section=' + cttcIndustry.getSection() + '&ref=' + encodeURIComponent(window.location.href), cttcIndustry.insertOrangeCol);
            }
        },
        dbgIE6: function() {
            /*-----------------------------------------------------------------------------
            debugs and overrides some style issues with IE6
            -----------------------------------------------------------------------------*/
            if (((window.navigator.userAgent).toLowerCase()).indexOf('msie 6') > -1) {
                var elem, cN, apnd;
                var pxImg = '<img src="http://www.visitcalifornia.com/_images/holder.gif" style="width:1px" />';
                var elems = document.getElementsByTagName('div');
                var apndOver = ((document.body.className).toLowerCase()).indexOf('cttc__appendcontent') > -1;
                for (var i = 0; i < elems.length; i++) {
                    elem = elems[i];
                    apnd = apndOver && elem.parentNode && elem.parentNode.parentNode && elem.parentNode.parentNode.className && ((elem.parentNode.parentNode.className).toLowerCase()).indexOf('cttc__rightcolumn') > -1;
                    cN = (elem.className).toLowerCase();
                    if (cN.indexOf('cttc__c1') > -1) {
                        elem.innerHTML += pxImg;
                    } else if (cN.indexOf('cttc__c2') > -1) {
                        elem.innerHTML += pxImg;
                        elem.style.right = apnd ? '-240px' : '-10px';
                    } else if (cN.indexOf('cttc__c3') > -1) {
                        elem.innerHTML += pxImg;
                        elem.style.bottom = '-15px';
                        elem.style.right = apnd ? '-240px' : '-10px';
                    } else if (cN.indexOf('cttc__c4') > -1) {
                        elem.innerHTML += pxImg;
                        elem.style.bottom = '-15px';
                    } else if (cN.indexOf('cttc__s1') > -1) {
                        elem.innerHTML += pxImg;
                        if (apnd) elem.style.padding = '0px 0px 0px 230px';
                    } else if (cN.indexOf('cttc__s2') > -1) {
                        elem.innerHTML += pxImg;
                        elem.style.right = apnd ? '-235px' : '-5px';
                        elem.style.height = elem.parentNode.offsetHeight + 'px';
                    } else if (cN.indexOf('cttc__s3') > -1) {
                        elem.innerHTML += pxImg;
                        elem.style.bottom = '-15px';
                        if (apnd) elem.style.padding = '0px 0px 0px 230px';
                    } else if (cN.indexOf('cttc__s4') > -1) {
                        elem.innerHTML += pxImg;
                        elem.style.left = '-20px';
                        elem.style.height = elem.parentNode.offsetHeight + 'px';
                    } else if (cN.indexOf('cttc__g1') > -1) {
                        elem.innerHTML += pxImg;
                        if (apnd) elem.style.padding = '0px 0px 0px 10px';
                    } else if (cN.indexOf('cttc__g2') > -1) {
                        elem.innerHTML += pxImg;
                        elem.style.right = apnd ? '-230px' : '0px';
                        elem.style.zIndex = 1;
                        elem.style.height = elem.parentNode.offsetHeight + 'px';
                    } else if (cN.indexOf('cttc__g3') > -1) {
                        elem.innerHTML += pxImg;
                        elem.style.bottom = '-5px';
                        if (apnd) elem.style.padding = '0px 0px 0px 10px';
                    } else if (cN.indexOf('cttc__g4') > -1) {
                        elem.innerHTML += pxImg;
                        elem.style.height = elem.parentNode.offsetHeight + 'px';
                    } else if (cN.indexOf('cttc__ca') > -1) {
                        elem.style.height = elem.parentNode.offsetHeight + 'px';
                    } else if (cN.indexOf('cttc__content') > -1 && ((elem.parentNode.className).toLowerCase()).indexOf('cttc__rightcolumn') > -1 && elem.offsetHeight < 600) {
                        elem.style.height = '600px';
                    }
                }
            }
        }
    },
    insertOrangeCol: function(r) {
        /*=================================================================================
        inserts the ajaxed content onto the page if the content exists
        =================================================================================*/
        var rsp = new String(r);
        var res = rsp.trim();
        var placeContent = function() {
            document.body.className = 'cttc__appendContent';
            var cont = document.getElementById('cttc__contentAppend');
            if (cont) {
                cont.innerHTML = res;
                var mC = document.getElementById('cttc__content');
                var lH = cttcIndustry.getElementHeight(mC)
                var rH = cttcIndustry.getElementHeight(cont);
                if (rH > lH) mC.style.height = rH + 'px';
            }
            if (((window.navigator.userAgent).toLowerCase()).indexOf('msie 6') > -1) cttcIndustry.initialization.dbgIE6();
        }
        if (res != '' && ((window.location.href).toLowerCase()).indexOf('testscript') > -1) {
            var shrinkContent = function() {
                var cont = document.getElementById('cttc__content');
                if (!cont.getAttribute('_oiw')) cont.setAttribute('_oiw', cont.clientWidth - 40);
                var newW = parseFloat(cont.getAttribute('_oiw')) - 2;
                cont.style.width = newW + 'px';
                cont.setAttribute('_oiw', newW);
            }
            for (var t = 0; t < 110; t++) setTimeout(shrinkContent, t * 5);
            setTimeout(placeContent, (t + 1) * 5);
        }
        else if (res != '' /*&& ((window.navigator.userAgent).toLowerCase()).indexOf('msie 6') > -1*/) placeContent();
    },
    isSection: function(v) {
        /*=================================================================================
        Checks if a page is the url section.
        =================================================================================*/
        return v.toLowerCase() == (cttcIndustry.getSection()).toLowerCase();
    },

    getSection: function() {
        /*=================================================================================
        Defines the url variables in a cttcIndustry.library.urlVars and returns the section
        =================================================================================*/
        if (!cttcIndustry.library.urlSection) {
            var sp; var vars = ((window.location.search).replace('?', '')).split('&');
            cttcIndustry.library.urlSection = '';
            cttcIndustry.library.urlVars = new Array();
            for (var i = 0; i < vars.length; i++) {
                sp = vars[i].split('=');
                if (sp.length > 1) cttcIndustry.library.urlVars[i] = { name: sp[0], value: sp[1] }
                if (sp[0].toLowerCase() == 'section') cttcIndustry.library.urlSection = sp[1];
            }
        }
        return cttcIndustry.library.urlSection;
    },
    ajax: function(u, n) {
        /*=================================================================================
        Obtains content from an HTTP location and processes a function or inserts it into an object
        =================================================================================*/
        var pR = false;
        if (window.XMLHttpRequest) pR = new XMLHttpRequest();
        else if (window.ActiveXObject) try { pR = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { pR = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { } }
        else return false;
        pR.onreadystatechange = function() {
            if (pR.readyState == 4 && (pR.status == 200 || window.location.href.indexOf("http") == -1)) {
                if (typeof (n) == 'function') n(pR.responseText);
                else if (typeof (n) == 'object') n.innerHTML = pR.responseText;
                else document.getElementById(n).innerHTML = pR.responseText;
            }
        }
        pR.open('GET', u, true);
        pR.send(null);
    },
    /*=================================================================================
    Obtains elements by a class name
    =================================================================================*/
    getElementsByClassName: function(c, s, t) { var a = new Array(); if (!c) var c = ''; if (!s) var s = document.body; if (!t) var t = '*'; var elems = s.getElementsByTagName(t); for (ci = 0; ci < elems.length; ci++) if (((elems[ci].className).toLowerCase()).indexOf(c.toLowerCase()) > -1) a[a.length] = elems[ci]; return a; },
    /*=================================================================================
    Functions that determine width, height, left, top of an object
    =================================================================================*/
    getElementTop: function(Elem) { if (typeof (Elem) == 'string') { if (document.getElementById) var elem = document.getElementById(Elem); else if (document.all) var elem = document.all[Elem]; } else { var elem = Elem; } yPos = elem.offsetTop; tempEl = elem.offsetParent; while (tempEl != null) { yPos += tempEl.offsetTop; tempEl = tempEl.offsetParent; } return yPos; },
    getElementHeight: function(Elem) { if (typeof (Elem) == 'string') { if (document.getElementById) var elem = document.getElementById(Elem); else if (document.all) var elem = document.all[Elem]; } else { var elem = Elem; } if ((navigator.userAgent.indexOf("Opera 5") != -1) || (navigator.userAgent.indexOf("Opera/5") != -1)) { xPos = elem.style.pixelHeight; } else { xPos = elem.offsetHeight; } return xPos; },
    getElementLeft: function(Elem) { if (typeof (Elem) == 'string') { if (document.getElementById) var elem = document.getElementById(Elem); else if (document.all) var elem = document.all[Elem]; } else { var elem = Elem; } xPos = elem.offsetLeft; tempEl = elem.offsetParent; while (tempEl != null) { xPos += tempEl.offsetLeft; tempEl = tempEl.offsetParent; } return xPos; },
    getElementWidth: function(Elem) { if (typeof (Elem) == 'string') { if (document.getElementById) var elem = document.getElementById(Elem); else if (document.all) var elem = document.all[Elem]; } else { var elem = Elem; } if ((navigator.userAgent.indexOf("Opera 5") != -1) || (navigator.userAgent.indexOf("Opera/5") != -1)) { xPos = elem.style.pixelWidth; } else { xPos = elem.offsetWidth; } return xPos; }
}

function SideBarWidget() {
     var htm;    
     
	 htm = "<h5>Research Bulletins</h5>"
          + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"mailto:research@visitcalifornia.com?subject=Subscribe to Research Bulletin&body=Please subscribe me to the Research Bulletin.%0D%0DFirst Name:%0DLast Name:%0DCompany:%0DAddress:%0DCity:%0DState:%0DZip:%0DPhone Number:\" target=\"_blank\"><img src=\"../../B2B/Images/bt_subscribe2.jpg\" border=\"0\" alt=\"Subscribe to Research Bulletin\" /></a>";
	 
    htm += "<h5>Latest Research</h5>"
          + "<ul>";

     for (var i = 0; i < jsonLatest.CONTENT.length; i++) {
          htm += "<li><a href=\"" + jsonLatest.FILE[i].URL + "\" target=\"_blank\">" + jsonLatest.CONTENT[i].NAME + "</a></li>";
     }

     htm += "<li><a href=\"/AM/Template.cfm?Section=Latest_Research1\">Other Recent Research...</a></li>"
          + "</ul>";
		  
	var htmTopics = jsonTopics.CONTENT[0].BODY;
     var p = htmTopics.toLowerCase().lastIndexOf("</ul>");	  
		  
	htmTopics = htmTopics.substr(0,p)
          + "<li><a href=\"/AM/Template.cfm?Section=Hot_Topics1\">Previous Hot Topics...</a></li>"
          + htmTopics.substr(p);

     htm += "<h5>Hot Topics</h5>"
          + htmTopics;

        var rsp = htm;
        var res = rsp.trim();
        var placeContent = function() {
            document.body.className = 'cttc__appendContent';
            var cont = document.getElementById('cttc__contentAppend');
            if (cont) {
                cont.innerHTML = res;
                var mC = document.getElementById('cttc__content');
                var lH = cttcIndustry.getElementHeight(mC)
                var rH = cttcIndustry.getElementHeight(cont);
                if (rH > lH) mC.style.height = rH + 'px';
            }
            if (((window.navigator.userAgent).toLowerCase()).indexOf('msie 6') > -1) cttcIndustry.initialization.dbgIE6();
        }
        if (res != '' && ((window.location.href).toLowerCase()).indexOf('testscript') > -1) {
            var shrinkContent = function() {
                var cont = document.getElementById('cttc__content');
                if (!cont.getAttribute('_oiw')) cont.setAttribute('_oiw', cont.clientWidth - 40);
                var newW = parseFloat(cont.getAttribute('_oiw')) - 2;
                cont.style.width = newW + 'px';
                cont.setAttribute('_oiw', newW);
            }
            for (var t = 0; t < 110; t++) setTimeout(shrinkContent, t * 5);
            setTimeout(placeContent, (t + 1) * 5);
        }
        else if (res != '' /*&& ((window.navigator.userAgent).toLowerCase()).indexOf('msie 6') > -1*/) placeContent();
}
