
if (window.location.toString().indexOf('empirestaging') < 0) {
    try {
        var pageTracker = _gat._getTracker("UA-8172933-1");
        pageTracker._trackPageview();
    } 
    catch (err) {
    }
}

$(document).ready(function(){

    isIE6_7 = false;
    jQuery.each(jQuery.browser, function(i, val){
        if ((i == "msie" && jQuery.browser.version.substr(0, 1) == "7") || (i == "msie" && jQuery.browser.version.substr(0, 1) == "6")) {
            isIE6_7 = true;
        }
    });
    
    // do not create special language dropdown in IE6/7 as a result of a z-index bug
    if (!isIE6_7) {
			//create the image dropdown for header
      $("#languageForm select").msDropDown();
		}
    
    
    (function($){
        $.fn.stripHtml = function(){
            var regexp = /<("[^"]*"|'[^']*'|[^'">])*>/gi;
            this.each(function(){
                $(this).html($(this).html().replace(regexp, ''));
            });
            return $(this);
        }
    })(jQuery);
    
    $('.stbuttontext').html('Share');
    
    /* Clear Search text on Focus */
    $('#search').focus(function(){
        $(this).val('');
    })
    
    jQuery('.hlist ul').superfish({
        autoArrows: false,
        dropShadows: false,
        animation: {
            height: 'show'
        },
        speed: 'fast',
        delay: 500
    });
    
    /* parse the returned news */
    $('#media_browser_nav a').click(function(){
        var newsTypeID = $(this).attr('rel');
        var resultLimit = '3';
        /* Date array for building formatted date */
        var m_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec");
        
        /*get the actual query in json format */
        $.getJSON('/remote/RemoteNewsService.cfc?method=getNews&returnformat=json&queryFormat=column&resultLimit=' + resultLimit + '&newsTypeID=' + newsTypeID, function(data){
        
            /*Empty the HTML container , we are replacing */
            $('#content_window').empty();
            
            /*empty out the selected from the news type tabs */
            jQuery.each($('#media_browser_nav li'), function(i, obj){
                obj.className = '';
            })
            
            //select the current news type tab
            $('#newsType_' + newsTypeID).addClass('active');
            
            HTML = '';
            /*Manually Build the HTML to replace the old HTMl */
            /*first check there are records returned */
            if (data.ROWCOUNT > 0) {
                for (var i = 0; i < data.ROWCOUNT; i++) {
                
                    HTML += '<div class="media_item">';
                    HTML += '<div class="subcolumns">';
                    HTML += '<div class="c25l">';
                    HTML += '<div class="subcl">';
                    /*Manually builing the formatted date */
                    var now = new Date(data.DATA['DATE_PUBLISHED'][i]);
                    var formattedDate = now.getDate() + ' ' + m_names[now.getMonth()] + ' ' + now.getFullYear();
                    HTML += '<p class="date">' + formattedDate + '</p>';
                    HTML += '<p></p>';
                    HTML += '</div>';
                    HTML += '</div>';
                    HTML += '<div class="c75r">';
                    HTML += '<div class="subcr">';
                    HTML += '<p><a href="/media_room/news/' + data.DATA['NEWS_ID'][i] + '"><span class="small_text">' + data.DATA['TITLE'][i] + '</span></a></p>';
                    HTML += '</div>';
                    HTML += '</div>';
                    HTML += '</div>';
                    HTML += '</div>';
                    
                }
                // add the more news button
                HTML += '<a href="/?e=news.list&amp;news_type_id=' + newsTypeID + '" class="more_news"><span class="hideme">More News</span></a>';
                
            }
            else {
                /*if there are no record show friendly error message */
                HTML += '<div class="media_item"><div class="subcolumns">';
                HTML += '<div class="c25l">';
                HTML += '<div class="subcl">';
                HTML += '<p class="date"></p>';
                HTML += '<p></p>';
                HTML += '</div>';
                HTML += '</div>';
                HTML += '<div class="c75r">';
                HTML += '<div class="subcr">';
                HTML += '<p>';
                HTML += '<span>There are currently no news items in this category.</span>';
                HTML += '</p>';
                HTML += '</div>';
                HTML += '</div>';
                HTML += '</div>';
                HTML += '</div>';
            }
            
            /* replace the old HTML with whats created above */
            $('#content_window').html(HTML);
        });
        return false;
        
    });
    
    
    /* events widget on homepage */
    $('#event_display_content a#prev_event, #event_display_content a#next_event').click(function(){
        var eventIndexID = $(this).attr('rel');
        /* Date array for building formatted date */
        
        /*get the actual query in json format */
        $.getJSON('/remote/RemoteEventsService.cfc?method=getEventForWidget&returnformat=json&queryFormat=column&eventIndexID=' + eventIndexID, function(data){
        
            /*Empty the HTML container , we are replacing */
            $('#content_window p').empty();
            
            /*Manually Build the HTML to replace the old HTML */
            $('#prev_event').attr('rel', data['PREVIOUSINDEXID']);
            $('#next_event').attr('rel', data['NEXTINDEXID']);
            HTML = '<a href="/media_room/events/' + data['EVENT_ID'] + '">' + data['TITLE'] + '</a>';
            
            /* replace the old HTML with whats created above */
            $('#content_window p:first').html(HTML);
        });
        
        return false;
    });
    
    $('.faq_answer').hide();
    $('.faq_question').toggle(function(){
        $(this).next().slideDown();
        $(this).addClass('faq_question_down');
    }, function(){
        $(this).next().slideUp();
        $(this).removeClass('faq_question_down');
    });
});
