var addthis_pub  = 'rightnow';
var addthis_hide_embed = false;
function makeCookie( name, data)
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );
/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
expires = 5 * 1000 * 60;
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name + "=" +escape( data ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) ;
}

function readCookie(cookieName){
   var searchName = cookieName + "="
   var cookies = document.cookie
   var start = cookies.indexOf(cookieName)
   if (start == -1){ // cookie not found 
     return ""
     }
   start += searchName.length //start of the cookie data
   var end = cookies.indexOf(";", start)
   if (end == -1){
     end = cookies.length
     }
   return cookies.substring(start, end)
   }
jQuery.noConflict();
jQuery(document).ready(function($){
//(function(){
    
//var $ = jQuery;
/***  Pretty Photo LightBox Effect JQuery code  ******/
if(document.getElementById('prettyPhoto')){
        (function(){
            alert("here I am");
           $("a[rel^='prettyPhoto']").prettyPhoto({theme: 'dark_rounded'});    }) ();
}

document.createElement('abbr'); //for IE?
$(document).ready(function(){
  //  $("a[rel^='prettyPhoto']").prettyPhoto();

       $('html').addClass('has-scripting');
    var searchInput = $("#search-input");
    if(searchInput.length && !searchInput.val())
        searchInput.val('Search');
    searchInput.focus(function(){
        if(!this.hasBeenClicked && this.value == 'Search'){
            this.value = "";
            this.hasBeenClicked = true;
        }
    });  
    
    $('div.action-items a.bookmark').mouseover(function(){
        addthis_open(this, '', '[URL]', '[TITLE]');
    }).click(function(){
        return addthis_sendto();
    }).mouseout(function(){
        addthis_close();
    });
    //### Profile Management ##########################################################################
    $("form#profile-management tr.hidden").hide();
    
    $("form#profile-management button[name=edit]").click(function (e)
      {
        if ($("form#profile-management tr.hidden").is(":hidden"))
        {
          $("form#profile-management tr.hidden").show();
          $("form#profile-management tr.tohide").hide();
          $("form#profile-management input").removeClass("flattenInput").attr("readonly", "");
          //$("form#profile-management input:third").focus();
          $("form#profile-management button:first").html("Save");
          e.preventDefault();
        }
      }
    );
    
    $("form#profile-management button[name=cancel]").click(function (e)
      {
        $("form#profile-management tr.hidden").hide();
        $("form#profile-management tr.tohide").show();
        $("form#profile-management input").addClass("flattenInput").attr("readonly", "readonly");
        $("form#profile-management button:first").html("Edit");
        e.preventDefault();
      }
    );    
        
    $("form#profile-management").submit(function(e)
      {
        $("form#profile-management td.leftCol").removeClass("error");
        
        $("form#profile-management input[type=text]").each(function()
          {
            if ($(this).val() == "")
            {
              $(this).parent().prev().addClass("error");
              $("div#profile-management-errors-blank").show(); 
              e.preventDefault();
            }
          }
        );
        
        $("form#profile-management select").each(function()
          {
            if ($(this).val() == "")
            {
              $(this).parent().prev().addClass("error");
              $("div#profile-management-errors-blank").show(); 
              e.preventDefault();
            }
          }
        );
        
        if ($("form#profile-management input[name=password]").val() != $("form#profile-management input[name=passwordConfirm]").val())
        {
          $("div#profile-management-errors-password").show(); 
          e.preventDefault();
        }
      }
    );
    //##########################################################################
    
    $('#left-column .customer-experience-strategies-widget h2, #left-column .solve-your-problem-widget h2').each(function(){
        var h2 = $(this);
        var li = $(this.parentNode);
        var ul = li.find(">ul");
        
        /*var toggler = document.createElement('span');
        toggler.className = 'expander';*/
        
        function toggle(){
            li.parent().find("> li").each(function(){
                if(li.attr('class') == $(this).attr('class'))
                    return;
                /*$(this).find("> h2 .expander").html("?");*/
                $(this).removeClass('expanded');
            });
            
            if(li.hasClass('expanded')){
                /*$(toggler).html('?');*/
                li.removeClass('expanded');
            }
            else {
                /*$(toggler).html('?');*/
                li.addClass('expanded');
            }
            
        }
        
        //if(li.hasClass('expanded')){
        //    $(toggler).html('?');
        //    //ul.show();
        //}
        //else {
        //    $(toggler).html('?')
        //    //ul.hide();
        //}
        this.onmousedown = /*toggler.onmousedown = */h2.onselectstart = /*toggler.onselectstart = */function(){return false};
        
        //this.parentNode.insertBefore(toggler, ul[0]);
        /*h2[0].appendChild(toggler);*/
        /*$(toggler).click(toggle);*/
        h2.click(toggle);
        
    });
    
    $('#briefcase-management input[name="select-all"]').click(function(){
        var isChecked = this.checked;
        $('#briefcase-management tbody input[type=checkbox]').each(function(){
            this.checked = isChecked;
        });
    });
    //$('#briefcase-management td.item').click(function(){
    //    var checkbox = $(this).parent().find('> td input')[0];
    //    checkbox.checked = !checkbox.checked;
    //});
    
    //Shadowbox.init({
    //    loadingImage:"/loading.gif",
    //    overlayBgImage:"/overlay-85.png"
    //    //,animate:false
    //});
    //Make sure that scrollbar appears initially in WebKit
    if($(document.body).hasClass('template-lightbox')){
        window.scrollTo(0,1);
        window.scrollTo(0,0);
    }
    
    //Tooltips
    $("h5 a[title]").tooltip({
        //bodyHandler: function() {
        //    return '<span class=border-left></span>' + this.tooltipText + '<span class=border-right></span>';
        //},
        //extraClass:'bubble',
        //opacity:1.0,
        extraClass:"default",
        showURL: false,
        track:true,
        delay:0
    });
    
    $("#briefcase-management td:has(div.abstract) h4 a, div.asset-list ul li:has(div.abstract) h4 a").tooltip({
        bodyHandler:function(){
            return "<h3>" + $(this).html() +  "</h3><div class='abstract'>" + $(this).parent().parent().find('div.abstract').html() + "</div>";
        },
        extraClass:"whitepaper",
        showURL: false,
        track:true,
        delay:0
    });
    
    $(".our-featured-clients img").tooltip({
        extraClass:"featured-client",
        showURL: false,
        track:true,
        delay:0
    });
    
    $('#con-channel-icons *').tooltip({
        extraClass: "default",
        showURL: false,
        track: true,
        delay:0
    });
    
    if($(document.body).hasClass('template-lightbox')){
        $('form.signin-form :input:first()').focus();
        $('form.ask-question :input:first()').focus();
    }
//Press Release filtering ###################################################################
if($('body').hasClass('template-pressroom')){
    var regexpHasPressRelease = /^Press Room Category:/;
    var regexpHasPrefix = /^.+?:/;
    $('#page-content > div.press-room-feed-section').each(function(section){
        var container = this;
        
        //Get the drop-down controls
        var yearSelect = $(this).find('select[name="date"]')[0];
        var categorySelect = $(this).find('select[name="category"]')[0];
        
        //Variables to store the possible options and the elements which have those options
        var categories = [];
        var categoryElements = {};
        var years = [];
        var yearElements = {};
        
        var lis = $(container).find('li');
        
        //Get all of the categories from the page, and get all of the items that go in each category
        lis.each(function(){ //.hentry
            var entry = this;
            
            //Parse the category tags
            $(entry).find('> a.entry-category').each(function(){
                if(!this.firstChild)
                    return;
                
                //Category tags are separated by commas 
                $(this.firstChild.nodeValue.split(/,/)).each(function(){
                    var label;
                    if(regexpHasPressRelease.test(this))
                        label = this.replace(regexpHasPressRelease, '');
                    else if(!regexpHasPrefix.test(this))
                        label = this;
                    if(label){
                        if(!categoryElements[label]){
                            categories.push(label);
                            if(!categoryElements[label])
                                categoryElements[label] = [];
                        }
                        categoryElements[label].push(entry);
                    }
                });
            });
            //Get the date
            var dateEl = $(entry).find('> .published')[0];
            if(dateEl){
                var mydate;
                if(dateEl.firstChild)
                    mydate = dateEl.firstChild.data;
                else //IE6
                    mydate = dateEl.nextSibling.data;
                if(mydate != undefined)
                {
                    var year = mydate.substr(mydate.length-4, 4);
                    if(!yearElements[year]){
                        years.push(year);
                        if(!yearElements[year])
                            yearElements[year] = [];
                    }
                    yearElements[year].push(entry);
                }
            }
        });
        
        //Sort the values and populate the drop-down lists
        var getMyCategory;
        $(categories.sort()).each(function(){
            var getMyCategory = readCookie('myCategory');
            if(getMyCategory == this)
                var defSel = true;
            else
                var defSel = false;                                           
            categorySelect.options.add(new Option(this, this, false, defSel));
        });
        var getMyYear;
        $(years/*.sort()*/).each(function(){
            var getMyYear = readCookie('myYear');
            if(getMyYear == this)
                var defSel = true;
            else
                var defSel = false;
            yearSelect.options.add(new Option(this, this, false, defSel));
        });
        
        //alert(document.cookie);
        
        //If no drop-downs are selected, then show every item (since no filter is provided)
            if(yearSelect.selectedIndex <= 0 && categorySelect.selectedIndex <= 0){
              
            }
            else {
                lis.hide();
                //Year only selected
                if(yearSelect.selectedIndex > 0 && categorySelect.selectedIndex <= 0){
                    $(yearElements[$(yearSelect).val()]).stop().show();
                }
                //Asset type only selected
                else if(categorySelect.selectedIndex > 0 && yearSelect.selectedIndex <= 0){
                    $(categoryElements[$(categorySelect).val()]).stop().show();
                }
                //Both are selected: if two drop downs (or more) are selected, then chained jQuery 
                //   selectors are combined to filter the results down to items which match all of 
                //   the selected drop-down values.
                else {
                    var els1 = $(yearElements[$(yearSelect).val()]);
                    var els2 = $(categoryElements[$(categorySelect).val()]);
                    var shown = els1.filter(function(){
                        var inEls2 = false;
                        var that = this;
                        $(els2).each(function(){
                            inEls2 = (this == that);
                            return !inEls2;
                        });
                        return inEls2;
                    }).stop().show().length;
                    
                    if(!shown)
                        notFound.fadeIn();
                }
                
            }
        
        //Create and append a new list item which is shown when no items match the filter selection
        var notFound = $('<li style="display:none"><em>No items matched your filter selections.</em></li>');
        $(this).find('ul:first').append(notFound);
        
        //Behavior of filter when form Submitted
        $(container).find('form:first').submit(function(e){
            //re-hide the not found notice
            notFound.hide();
                        
            //If no drop-downs are selected, then show every item (since no filter is provided)
            if(yearSelect.selectedIndex <= 0 && categorySelect.selectedIndex <= 0){
                makeCookie('myYear', ''); 
                lis.show();
            }
            else {
                lis.hide();
                //Year only selected
                if(yearSelect.selectedIndex > 0 && categorySelect.selectedIndex <= 0){
                    makeCookie('myYear', yearSelect.options[yearSelect.selectedIndex].value); 
                    makeCookie('myCategory', ''); 
                    $(yearElements[$(yearSelect).val()]).stop().show();
                }
                //Asset type only selected
                else if(categorySelect.selectedIndex > 0 && yearSelect.selectedIndex <= 0){
                    makeCookie('myCategory', categorySelect.options[categorySelect.selectedIndex].value); 
                    makeCookie('myYear', ''); 
                    $(categoryElements[$(categorySelect).val()]).stop().show();
                }
                //Both are selected: if two drop downs (or more) are selected, then chained jQuery 
                //   selectors are combined to filter the results down to items which match all of 
                //   the selected drop-down values.
                else {
                    makeCookie('myYear', yearSelect.options[yearSelect.selectedIndex].value); 
                    makeCookie('myCategory', categorySelect.options[categorySelect.selectedIndex].value); 
                    var els1 = $(yearElements[$(yearSelect).val()]);
                    var els2 = $(categoryElements[$(categorySelect).val()]);
                    var shown = els1.filter(function(){
                        var inEls2 = false;
                        var that = this;
                        $(els2).each(function(){
                            inEls2 = (this == that);
                            return !inEls2;
                        });
                        return inEls2;
                    }).stop().show().length;
                    
                    if(!shown)
                        notFound.fadeIn();
                }  
            }
            e.preventDefault();
            
        });
    });
   }
//REMOVED (RelatedInformation handles it): Content Library Filtering ########################################################################
//else if(false&&$('body').hasClass('template-contentlibrary')){
//try {
//    var lookupAssets = {};
//    var lookupApplications = {};
//    var lookupIndustries = {};
//    var assetNames = [];
//    var applicationNames = [];
//    var industryNames = [];
//    
//    var select_assetType = $('#page-content select[name="asset-type"]');
//    var select_industry = $('#page-content select[name="industry"]');
//    var select_application = $('#page-content select[name="application"]');
//    
//    var lis = $('body.template-contentlibrary #page-content .asset-list li');
//    lis.each(function(){
//        if(!this.dataset) //HTML5
//            this.dataset = {};
//            
//        //Asset Type
//        var assetTypeName = $(this).find('h4 > .type').text().replace(/\s*:\s*/, '');
//        if(assetTypeName && !lookupAssets[assetTypeName]){
//            lookupAssets[assetTypeName] = true;
//            assetNames.push(assetTypeName);
//        }
//        this.dataset.assetTypeName = assetTypeName;
//        
//        //Application
//        var applicationName = $(this).find('.meta .application').text();
//        if(applicationName && !lookupApplications[applicationName]){
//            lookupApplications[applicationName] = true;
//            applicationNames.push(applicationName);
//        }
//        this.dataset.applicationName = applicationName;
//        
//        //Industry
//        var industryName = $(this).find('.meta .industry').text();
//        if(industryName && !lookupIndustries[industryName]){
//            lookupIndustries[industryName] = true;
//            industryNames.push(industryName);
//        }
//        this.dataset.industryName = industryName;
//        
//        
//    });    
//    //Asset Type
//    if(select_assetType[0]){
//        assetNames = assetNames.sort();
//        $(assetNames).each(function(){
//            select_assetType[0].options.add(new Option(this));
//        });
//    }
//    //Application
//    if(select_application[0]){
//        applicationNames = applicationNames.sort();
//        $(applicationNames).each(function(){
//            select_application[0].options.add(new Option(this));
//        });
//    }
//    //Application
//    if(select_industry[0]){
//        industryNames = industryNames.sort();
//        $(industryNames).each(function(){
//            select_industry[0].options.add(new Option(this));
//        });
//    }
//    
//    
//    //Show or hide the items when the form is submitted
//    $('body.template-contentlibrary #page-content form').submit(function(e){
//        var selectedApplication;
//        if(select_application[0] && select_application[0].selectedIndex > 0)
//            selectedApplication = select_application.val();
//        
//        var selectedIndustry;
//        if(select_industry[0] && select_industry[0].selectedIndex > 0)
//            selectedIndustry = select_industry.val();
//        
//        var selectedAssetType;
//        if(select_assetType[0] && select_assetType[0].selectedIndex > 0)
//            selectedAssetType = select_assetType.val();
//        
//        //Iterate over all of the items
//        lis.each(function(){
//            var doShow = true;
//            
//            if(selectedApplication && selectedApplication != this.dataset.applicationName)
//                doShow = false;
//            else if(selectedIndustry && selectedIndustry != this.dataset.industryName)
//                doShow = false;
//            else if(selectedAssetType && selectedAssetType != this.dataset.assetTypeName)
//                doShow = false;
//            
//            if(doShow)
//                $(this).slideDown();
//            else
//                $(this).slideUp();
//        });
//        e.preventDefault();
//    });
//}catch(e){alert(e.description + e.toString())}
//}
//Events Filtering ########################################################################
else if($('body').hasClass('template-events')){
    (function(){
    var selectEventType = $('#page-content select[name="event-type"]')[0];
    var selectMonth = $('#page-content select[name="month"]')[0];
    if(!selectEventType || !selectMonth)
        return;
    
    var eventTypes = [];
    var eventTypeElements = {};
    var months = ['January', 'Feburary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    var monthElements = {};
    
    var lis = $('#page-content ul.event-list li.vevent');
    if(lis.length == 0)
    {
        $('#page-content p[class="filter-controls"]').hide();
        // Per Mariska - do not show "No Events" message.
        //var notFound = $('<li style="display:none" class="no-results"><em>No events currently planned, please try back later.</em></li>');
        //$('#page-content ul.event-list').append(notFound);
        //notFound.fadeIn();
    }
    lis.each(function(){
        //Start Date
        var date = $(this).find('.date *[title!=""]').attr('title');
        if(date){
            var matches = date.match(/\d\d\d\d-(\d\d)-\d\d/);
            if(matches){
                var month = parseInt(matches[1], 10);
                if(!monthElements[month]){
                    monthElements[month] = [];
                    //eventTypes.push(dateMatches[0]);
                }
                monthElements[month].push(this);
            }
        }
        
        //Event Type
        var li = this;
        $($(this).find('.category').text().split(/\s*,\s*/)).each(function(){
            if(/^Event Type:/.test(this)){
                var eventType = this.replace(/^.+?:\s*/, '');
                if(!eventTypeElements[eventType]){
                    eventTypeElements[eventType] = [];
                    eventTypes.push(eventType);
                }
                eventTypeElements[eventType].push(li);
            }
        });
    });
    
    $(eventTypes.sort()).each(function(){
        var getMyEventType = readCookie('myEventType');
        if(unescape(getMyEventType) == this)
            var defSel = true;
        else
            var defSel = false;                                           
        selectEventType.options.add(new Option(this, this, false, defSel));                                       
        
    });
    $(months).each(function(i){
        var getMyMonth = readCookie('myMonth');
        if(getMyMonth == (i+1))
            var defSel = true;
        else
            var defSel = false;                                           
        selectMonth.options.add(new Option(this, i+1, false, defSel));                                
    });
    
    if(selectEventType.selectedIndex <= 0 && selectMonth.selectedIndex <= 0){
        lis.show();
    }
    else {
        lis.slideUp();
        //EventType only selected
        if(selectEventType.selectedIndex > 0 && selectMonth.selectedIndex <= 0){
            if(!$(eventTypeElements[$(selectEventType).val()] || []).stop().slideDown().length)
                notFound.fadeIn();
        }
        //Month only selected
        else if(selectMonth.selectedIndex > 0 && selectEventType.selectedIndex <= 0){
            if(!$(monthElements[$(selectMonth).val()] || []).stop().slideDown().length){
                notFound.fadeIn();
            }
        }
        //Both are selected
        else {
            var els1 = $(monthElements[$(selectMonth).val()] || []);
            var els2 = $(eventTypeElements[$(selectEventType).val()] || []);
            var shown = els1.filter(function(){
                var inEls2 = false;
                var that = this;
                $(els2).each(function(){
                    inEls2 = (this == that);
                    return !inEls2;
                });
                return inEls2;
            }).stop().slideDown().length;
            
            if(!shown)
                notFound.fadeIn();
        }
    }
            
    var notFound = $('<li style="display:none" class="no-results"><em>No events matching selected filter</em></li>');
    $('#page-content ul.event-list').append(notFound);
    
    $('#page-content form').submit(function(e){
        notFound.hide();
        if(selectEventType.selectedIndex <= 0 && selectMonth.selectedIndex <= 0){
            makeCookie('myEventType', ''); 
            makeCookie('myMonth', ''); 
            lis.show();
        }
        else {
            lis.slideUp();
            //EventType only selected
            if(selectEventType.selectedIndex > 0 && selectMonth.selectedIndex <= 0){
                if(!$(eventTypeElements[$(selectEventType).val()] || []).stop().slideDown().length)
                    notFound.fadeIn();
                else {
                    makeCookie('myEventType', selectEventType.options[selectEventType.selectedIndex].value); 
                    makeCookie('myMonth', ''); 
                }
            }
            //Month only selected
            else if(selectMonth.selectedIndex > 0 && selectEventType.selectedIndex <= 0){
                if(!$(monthElements[$(selectMonth).val()] || []).stop().slideDown().length){
                    notFound.fadeIn();
                }
                else {
                    makeCookie('myEventType', ''); 
                    makeCookie('myMonth', selectMonth.options[selectMonth.selectedIndex].value); 
                }
            }
            //Both are selected
            else {
                makeCookie('myEventType', selectEventType.options[selectEventType.selectedIndex].value); 
                makeCookie('myMonth', selectMonth.options[selectMonth.selectedIndex].value); 
                var els1 = $(monthElements[$(selectMonth).val()] || []);
                var els2 = $(eventTypeElements[$(selectEventType).val()] || []);
                var shown = els1.filter(function(){
                    var inEls2 = false;
                    var that = this;
                    $(els2).each(function(){
                        inEls2 = (this == that);
                        return !inEls2;
                    });
                    return inEls2;
                }).stop().slideDown().length;
                
                if(!shown)
                    notFound.fadeIn();
            }
            
        }
        e.preventDefault();
    });
    })();//end closure
}
// Briefcase ######################################################################3
else if($('body').hasClass('template-briefcase')){
    $("body.template-briefcase p.message").animate(
    {
      backgroundColor: "#D68023",
      color: "black"
    }, 300).animate(
    {
      backgroundColor: "white",
      color: "#666666"
    }, 4000 );
    $("button[@name='download']").click(function(){
        var checks = $("form#briefcase-management input[type='checkbox']");
        for (var i = 0; i < checks.length; i++)
        {
          if($(checks[i]).attr("name") != "select-all")
          {
            if (checks[i].checked)
            {
              return true;
            }
          }
        }
        alert ("Please check an item you'd like to download");
        return false;
    });
}
// Partners Directory ###########################################################################################################
else if($('body').hasClass('template-client-showcase')){
    (function(){
    var container = $('#page-content div.more-clients');
    if(!container.length)
        return;
    var form = container.find('form');
    
    var selectGeography = container.find('select[name="geography"]')[0];
    var geographies = [];
    var geographyElements = {};
    var selectSolution = container.find('select[name="solution"]')[0];
    var solutions = [];
    var solutionElements = {};
    if(!selectGeography || !selectSolution)
        return;
    
    var lis = container.find('li');
    lis.each(function(){
        //Asset Type
        var solution = $(this).find('.meta .solution').text();
        if(solution){
         var that = this;
            $(solution.split(/\s*,\s*/)).each(function(){
                var val = this.replace(/^\s+|\s+$/g,'');
                if(!solutionElements[val]){
                    solutions.push(val);
                    solutionElements[val] = [];
                }
                solutionElements[val].push(that); 
            });
        }
        
        //Geography
        var geography = $(this).find('.meta .geography').text();
        if(geography){
         var that = this;
            $(geography.split(/\s*,\s*/)).each(function(){
                var val = this.replace(/^\s+|\s+$/g,'');
                if(!geographyElements[val]){
                    geographies.push(val);
                    geographyElements[val] = [];
                }
                geographyElements[val].push(that); 
            });
        }
    });
    $(solutions.sort()).each(function(){
        selectSolution.options.add(new Option(this));
    });
    $(geographies.sort()).each(function(){
        selectGeography.options.add(new Option(this));
    });
    
    var notFound = $('<li style="display:none"><em>No items matched your filter selections.</em></li>');
    container.find('ul').append(notFound);
    
    form.submit(function(e){
        notFound.hide();
        if(selectSolution.selectedIndex <= 0 && selectGeography.selectedIndex <= 0){
            lis.show();
        }
        else {
            lis.slideUp();
            //Geography only selected
            if(selectGeography.selectedIndex > 0 && selectSolution.selectedIndex <= 0){
                $(geographyElements[$(selectGeography).val()]).stop().slideDown();
            }
            //Asset type only selected
            else if(selectSolution.selectedIndex > 0 && selectGeography.selectedIndex <= 0){
                $(solutionElements[$(selectSolution).val()]).stop().slideDown();
            }
            //Both are selected
            else {
                var els1 = $(geographyElements[$(selectGeography).val()]);
                var els2 = $(solutionElements[$(selectSolution).val()]);
                var shown = els1.filter(function(){
                    var inEls2 = false;
                    var that = this;
                    $(els2).each(function(){
                        inEls2 = (this == that);
                        return !inEls2;
                    });
                    return inEls2;
                }).stop().slideDown().length;
                
                if(!shown)
                    notFound.fadeIn();
            }
            
        }
        e.preventDefault();
    });
    })();
}
// Client Showcase Filtering ######################################################################3
if($('body').hasClass('template-client-showcase')){
    (function(){
    var form = $('#page-content div.more-clients form');
    if(!form.length)
        return;
    
    var selectIndustry = form.find('select[name="industry"]')[0];
    var industries = [];
    var industryElements = {};
    var selectApplication = form.find('select[name="application"]')[0];
    var applications = [];
    var applicationElements = {};
    if(!selectIndustry || !selectApplication)
        return;
    
    var items = $('#page-content div.more-clients li');
    items.each(function(){
        var industry = $(this).find('.meta .industry').text();
        if(industry){
            
            var industryArray = industry.split(',');
            var arLen=industryArray.length;
            var application = "";
            var industry = "";
            for(var i=0; i<arLen; i++)
            {
                var splitArray = industryArray[i].split(':');
                var splitLen = splitArray.length;
                for(var j=0; j<splitLen; j++)
                {    
                    var x = j;
                    x++;
                    if(splitArray[j] == 'Application')
                    {
                        if(application == "") 
                            application = splitArray[x];
                        else
                            application = application + ";" + splitArray[x];
                    }
                    else if (splitArray[j] == 'Industry')
                    {
                        if(industry == "") 
                            industry = splitArray[x];
                        else
                            industry = industry + ";" + splitArray[x];
                    }
                }
            }
            
            var indSplit = industry.split(';');
            var indLen = indSplit.length;
            for(k=0; k<indLen; k++)
            {
                industry = indSplit[k];
                if(!industryElements[industry]){
                    industries.push(industry);
                    industryElements[industry] = [];
                }
                industryElements[industry].push(this);
                
            }
            $(this).find('.meta .application').after(application);
            var appSplit = application.split(';');
            var appLen = appSplit.length;
            for(k=0; k<appLen; k++)
            {
                application = appSplit[k];
                if(application){
                    if(!applicationElements[application]){
                        applications.push(application);
                        applicationElements[application] = [];
                    }
                    applicationElements[application].push(this);
                }
            }
        }
    });
    
    var notFound = $("<li><em>No results matched your filter selection</em></li>").hide();
    $('#page-content div.more-clients ul').append(notFound);
    
    var getMyIndustry;
    $(industries.sort()).each(function(){
        var getMyIndustry = readCookie('myIndustry');
        if(unescape(getMyIndustry) == this)
            var defSel = true;
        else
            var defSel = false;                                       
        selectIndustry.options.add(new Option(this, this, false, defSel));
    });
    var getMyAppl;
    $(applications.sort()).each(function(){
        var getMyAppl = readCookie('myApplication');
        if(unescape(getMyAppl) == this)
            var defSel = true;
        else
            var defSel = false;                                             
        selectApplication.options.add(new Option(this, this, false, defSel));
    });
    
    // Load the selected items that match the values from the cookie.
    if(selectIndustry.selectedIndex <= 0 && selectApplication.selectedIndex <= 0){
            items.show();
        }
        else {
            var industry = $(selectIndustry).val();
            var application = $(selectApplication).val();
            
            items.slideUp();
            //Both are selected
            if(selectIndustry.selectedIndex > 0 && selectApplication.selectedIndex > 0){
                var count = $(applicationElements[application]).filter(function(){
                    var that = this;
                    return !!$(industryElements[industry]).filter(function(){
                        return this == that;
                    }).length;
                }).stop().slideDown().length;
                
                if(!count)
                    notFound.fadeIn();
            }
            //Industry is selected
            else if(selectIndustry.selectedIndex > 0){
                $(industryElements[industry]).stop().slideDown();
            }
            //Application is selected
            else if(selectApplication.selectedIndex > 0){
                $(applicationElements[application]).stop().slideDown();
            }
        }
        //e.preventDefault();
        
    form.submit(function(e){
        notFound.hide();
        if(selectIndustry.selectedIndex <= 0 && selectApplication.selectedIndex <= 0){
            makeCookie('myIndustry', ''); 
            makeCookie('myApplication', ''); 
            items.show();
        }
        else {
            var industry = $(selectIndustry).val();
            var application = $(selectApplication).val();
            
            items.slideUp();
            //Both are selected
            if(selectIndustry.selectedIndex > 0 && selectApplication.selectedIndex > 0){
                makeCookie('myIndustry', selectIndustry.options[selectIndustry.selectedIndex].value); 
                makeCookie('myAppliacation', selectApplication.options[selectApplication.selectedIndex].value); 
                var count = $(applicationElements[application]).filter(function(){
                    var that = this;
                    return !!$(industryElements[industry]).filter(function(){
                        return this == that;
                    }).length;
                }).stop().slideDown().length;
                
                if(!count)
                    notFound.fadeIn();
            }
            //Industry is selected
            else if(selectIndustry.selectedIndex > 0){
                makeCookie('myIndustry', selectIndustry.options[selectIndustry.selectedIndex].value); 
                makeCookie('myAppliacation', ''); 
                $(industryElements[industry]).stop().slideDown();
            }
            //Application is selected
            else if(selectApplication.selectedIndex > 0){
                makeCookie('myIndustry', ''); 
                makeCookie('myAppliacation', selectApplication.options[selectApplication.selectedIndex].value); 
                $(applicationElements[application]).stop().slideDown();
            }
        }
        e.preventDefault();
    });
    })();
}
    
// Related Information Filtering ###########################################################################################################
if(document.getElementById('related-information')){
    (function(){
try{
    var form = $('#related-information form');
    if(!form.length)
        return;
    
    var selectIndustry = $('#related-information select[name="industry"]')[0];
    var industries = [];
    var industryElements = {};
    var selectApplication = $('#related-information select[name="application"]')[0];
    var applications = [];
    var applicationElements = {};
    var selectAssetType = $('#related-information select[name="asset-type"]')[0];
    var assetTypes = [];
    var assetTypeElements = {};
    if(!selectIndustry && !selectApplication && !selectAssetType)
        return;
    
    var lis = $('#related-information li');
    
    lis.each(function(){
        //Asset Type
        var assetType = $(this).find('.type').text().replace(/:\s*$/, '');
        if(assetType){
            if(!assetTypeElements[assetType]){
                assetTypes.push(assetType);
                assetTypeElements[assetType] = [];
            }
            assetTypeElements[assetType].push(this);
        }
        
        //Industry
        var industry = $(this).find('.meta .industry').text();
        if(industry){
            var that = this;
            $(industry.split(/\s*,\s*/)).each(function(){
                var val = this.replace(/^\s+|\s+$/g,'');
                if(!industryElements[val]){
                    industries.push(val);
                    industryElements[val] = [];
                }
                industryElements[val].push(that); 
            });
        }
        
        //Application
        var application = $(this).find('.meta .application').text();
        if(application){
            var that = this;
            $(application.split(/\s*,\s*/)).each(function(){
                var val = this.replace(/^\s+|\s+$/g,'');
                if(!applicationElements[val]){
                    applications.push(val);
                    applicationElements[val] = [];
                }
                applicationElements[val].push(that); 
            });
        }
    });
    if(selectAssetType){
        $(assetTypes.sort()).each(function(){
            selectAssetType.options.add(new Option(this));
        });
    }
    if(selectIndustry){
        $(industries.sort()).each(function(){
            selectIndustry.options.add(new Option(this));
        });
    }
    if(selectApplication){
        $(applications.sort()).each(function(){
            selectApplication.options.add(new Option(this));
        });
    }
    
    var notFound = $('<li style="display:none"><em>No items matched your filter selections.</em></li>');
    $('#related-information ul').append(notFound);
    
    form.submit(function(e){
        var is_industrySelected = (selectIndustry && selectIndustry.selectedIndex > 0);
        var is_applicationSelected = (selectApplication && selectApplication.selectedIndex > 0);
        var is_assetTypeSelected = (selectAssetType && selectAssetType.selectedIndex > 0);
            
        notFound.hide();
        if(!is_industrySelected && !is_applicationSelected && !is_assetTypeSelected){
            lis.show();
        }
        else {
            lis.slideUp();
            //Industry only selected
            if(is_industrySelected && !is_applicationSelected && !is_assetTypeSelected){
                $(industryElements[$(selectIndustry).val()]).stop().slideDown();
            }
            //Asset type only selected
            else if(!is_industrySelected && !is_applicationSelected && is_assetTypeSelected){
                $(assetTypeElements[$(selectAssetType).val()]).stop().slideDown();
            }
            //Application only selected
            else if(!is_industrySelected && is_applicationSelected && !is_assetTypeSelected){
                $(applicationElements[$(selectApplication).val()]).stop().slideDown();
            }
            //Both are selected
            else {
                var els = [];
                if(is_industrySelected)
                    els.push($(industryElements[$(selectIndustry).val()]));
                if(is_applicationSelected)
                    els.push($(applicationElements[$(selectApplication).val()]));
                if(is_assetTypeSelected)
                    els.push($(assetTypeElements[$(selectAssetType).val()]));
                
                var shown = els[0].filter(function(){
                    var inEls2 = false;
                    var that = this;
                    $(els[1]).each(function(){
                        inEls2 = (this == that);
                        return !inEls2;
                    });
                    return inEls2;
                }).stop().slideDown().length;
                
                if(!shown)
                    notFound.fadeIn();
            }
            
        }
        e.preventDefault();
    });
}catch(e){alert(e.message + e.toString())}
    })();
}
// Module List Filtering ###########################################################################################################    
else if($('body').hasClass('template-clients')){
    (function(){
    var modules = $('#page-content div.module-list li');
    if(!modules.length)
        return;
    
    var select = $('#page-content div.module-list form select')[0]; //should be name=application
    
    $('#page-content div.module-list form').submit(function(e){
        if(select.selectedIndex <= 0){
            modules.show();
        }
        else {
            modules.slideUp();
            var selected = $(select).val();
            modules.filter(function(){
                return $(this).find('a.' + $(select).val()).length;
            }).stop().slideDown();
        }
        e.stopPropagation();
    });
    })();
}
});
//window.openLightbox = function(title, src, width, height){
//    Shadowbox.open({
//        title:title,
//        type:'iframe',
//        content:src,
//        height:height,
//        width:width
//    });
//    $('#shadowbox').append("<a id='shadowbox_title_close' href='javascript:Shadowbox.close();'>Close</a>");
//}
//http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:forEach
if (!Array.prototype.forEach)
{
  Array.prototype.forEach = function(fun /*, thisp*/)
  {
    var len = this.length;
    if (typeof fun != "function")
      throw new TypeError();
    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
        fun.call(thisp, this[i], i, this);
    }
  };
}
/**************************************************************
 * cross-browser CSS3 column lists implementation prototype
 * Weston Ruter, 2008-04-29
 * Requires jQuery
 ***************************************************************
var columnedEls = $('ul.css3-columns, ol.css3-columns'); //document.getElementsByClassName ? document.getElementsByClassName('ul.css3-columns') :
if(columnedEls.length){
    var firstLI = columnedEls[0].getElementsByTagName('li')[0];
    if(firstLI && firstLI.offsetWidth > columnedEls[0].offsetWidth / 2){ //determine if CSS3 colmns are supported
        columnedEls.each(function(){ //better if sniffed from style rule selectors
            this.style.columnCount = 0; //disable if by chance it has been implemented
            
            var children = $(this).children();
            
            var matches = this.className.match(/\bcolumn-count-(\d+)/);
            var columnCount = parseInt(matches[1]); // should be sniffed from style rules 
            
            var columnItemCount = Math.ceil((children.length)/columnCount);
            var itemHeight = children[0].offsetHeight;
            var columnWidth = Math.floor(this.offsetWidth/columnCount);
            var containerHeight = itemHeight*columnItemCount;
            
            for(var colNum = 0; colNum < columnCount; colNum++){
                var colEl = document.createElement('div');
                colEl.style.cssText = "float:left; width:" + columnWidth + "px";
                for(var i = colNum*columnItemCount; i < (colNum+1)*columnItemCount && i < children.length; i++){
                    colEl.appendChild(children[i].parentNode.removeChild(children[i]));
                }
                this.appendChild(colEl);
            }
            
            var clearFloat = document.createElement('div');
            clearFloat.style.clear = "both";
            this.parentNode.insertBefore(clearFloat, this.nextSibling);
        });
    }
}
//}
*/
/**** FishEye Effect on HomePage  *****/
if(document.getElementById('dockWrap')){
    (function(){
           var opts = { align:  'bottom'
                   , size: 80
                   , distance: 90
                   , coefficient : 1.5
                   , labels: false
                   , duration: 500
                   , source:  function(){ return (this.alt); }
                   };
        $('#dockIt').jqDock(opts);
    }) ();
}
/*** Forgot Password JQuery code ******/
if(document.getElementById('div#forgotPassword')){
   $('div#forgotPassword').hide();
}
/***  LightBox Effect JQuery code  ******/
if(document.getElementById('gallery')){
    (function(){
           var settings = { containerResizeSpeed: 350
            };
            $('#gallery a').lightBox(settings);
    }) ();
}

/**** Creates Columns on Page (homepage & policy)  ******/
var columnedEls = $('ul.css3-columns, ol.css3-columns'); //document.getElementsByClassName ? document.getElementsByClassName('ul.css3-columns') :
if(columnedEls.length){
    (function(){
            $('.css3-columns').makeacolumnlists({cols: 4, colWidth: 0, equalHeight: 'ul', startN: 1});
              }) ();
}
var columnedEls2 = $('ul.css3-columns-2, ol.css3-columns-2'); //document.getElementsByClassName ? document.getElementsByClassName('ul.css3-columns') :
if(columnedEls2.length){
    (function(){
            $('.css3-columns-2').makeacolumnlists({cols: 2, colWidth: 0, equalHeight: 'ul', startN: 1});
              }) ();
}
}); //();