(function($){$.fn.pajinate=function(options){var current_page="current_page";var items_per_page="items_per_page";var meta;var defaults={item_container_id:".content",items_per_page:10,nav_panel_id:".page_navigation",num_page_links_to_display:20,start_page:0,nav_label_first:"First",nav_label_prev:"Prev",nav_label_next:"Next",nav_label_last:"Last"};var options=$.extend(defaults,options);var $item_container;var $page_container;var $items;var $nav_panels;return this.each(function(){$page_container=$(this);$item_container=$(this).find(options.item_container_id);$items=$page_container.find(options.item_container_id).children();meta=$page_container;meta.data(current_page,0);meta.data(items_per_page,options.items_per_page);var total_items=$item_container.children().size();var number_of_pages=Math.ceil(total_items/options.items_per_page);var more='<span class="ellipse more"></span>';var less='<span class="ellipse less"></span>';var navigation_html='<a class="first_link" href="">'+options.nav_label_first+"</a>";navigation_html+='<a class="previous_link" href="">'+options.nav_label_prev+"</a>"+less;var current_link=0;while(number_of_pages>current_link){navigation_html+='<a class="page_link" href="" longdesc="'+current_link+'">'+(current_link+1)+"</a>";current_link++}navigation_html+=more+'<a class="next_link" href="">'+options.nav_label_next+"</a>";navigation_html+='<a class="last_link" href="">'+options.nav_label_last+"</a>";$nav_panels=$page_container.find(options.nav_panel_id);$nav_panels.html(navigation_html).each(function(){$(this).find(".page_link:first").addClass("first");$(this).find(".page_link:last").addClass("last")});$nav_panels.children(".ellipse").hide();$nav_panels.find(".previous_link").next().next().addClass("active_page");$items.hide();$items.slice(0,meta.data(items_per_page)).show();var total_page_no_links=$page_container.children(options.nav_panel_id+":first").children(".page_link").size();options.num_page_links_to_display=Math.min(options.num_page_links_to_display,total_page_no_links);$nav_panels.children(".page_link").hide();$nav_panels.each(function(){$(this).children(".page_link").slice(0,options.num_page_links_to_display).show()});$page_container.find(".first_link").click(function(e){e.preventDefault();movePageNumbersRight($(this),0);gotoPage(0)});$page_container.find(".last_link").click(function(e){e.preventDefault();var lastPage=total_page_no_links-1;movePageNumbersLeft($(this),lastPage);gotoPage(lastPage)});$page_container.find(".previous_link").click(function(e){e.preventDefault();showPrevPage($(this))});$page_container.find(".next_link").click(function(e){e.preventDefault();showNextPage($(this))});$page_container.find(".page_link").click(function(e){e.preventDefault();gotoPage($(this).attr("longdesc"))});gotoPage(parseInt(options.start_page));toggleMoreLess()});function showPrevPage(e){new_page=parseInt(meta.data(current_page))-1;if($(e).siblings(".active_page").prev(".page_link").length==true){movePageNumbersRight(e,new_page);gotoPage(new_page)}}function showNextPage(e){new_page=parseInt(meta.data(current_page))+1;if($(e).siblings(".active_page").next(".page_link").length==true){movePageNumbersLeft(e,new_page);gotoPage(new_page)}}function gotoPage(page_num){var ipp=meta.data(items_per_page);var isLastPage=false;start_from=page_num*ipp;end_on=start_from+ipp;$items.hide().slice(start_from,end_on).show();$page_container.find(options.nav_panel_id).children(".page_link[longdesc="+page_num+"]").addClass("active_page").siblings(".active_page").removeClass("active_page");meta.data(current_page,page_num);toggleMoreLess()}function movePageNumbersLeft(e,new_p){var new_page=new_p;var $current_active_link=$(e).siblings(".active_page");if($current_active_link.siblings(".page_link[longdesc="+new_page+"]").css("display")=="none"){$nav_panels.each(function(){$(this).children(".page_link").hide().slice(parseInt(new_page-options.num_page_links_to_display+1),new_page+1).show()})}}function movePageNumbersRight(e,new_p){var new_page=new_p;var $current_active_link=$(e).siblings(".active_page");if($current_active_link.siblings(".page_link[longdesc="+new_page+"]").css("display")=="none"){$nav_panels.each(function(){$(this).children(".page_link").hide().slice(new_page,new_page+parseInt(options.num_page_links_to_display)).show()})}}function toggleMoreLess(){if(!$nav_panels.children(".page_link:visible").hasClass("last")){$nav_panels.children(".more").show()}else{$nav_panels.children(".more").hide()}if(!$nav_panels.children(".page_link:visible").hasClass("first")){$nav_panels.children(".less").show()}else{$nav_panels.children(".less").hide()}}}})(jQuery);

function go(whereto, newWindow) {
    openNew = false;
    if(typeof newWindow != undefined) {
        openNew = newWindow;
    }
    
    if(openNew) {
        wind = window.open(whereto, '_blank');
        wind.focus();
    } else {
        window.location.href = whereto;  
    }
}
    

/**
 * Weather object
 *

A.PCLF	freely associated state	 */
Weather = {};


Weather.Main = {
    
    /**
     * Init
     *
     */
    init: function() {
        // Apply on hovers to small and large blocks
        $('.smallBlock').hover(function() {
            $(this).find('.caption').slideDown('fast');
        }, function() {
            $(this).find('.caption').slideUp(100);
        });
        
        
        $('.largeBlock').hover(function() {
            $(this).find('.caption').slideDown('fast');
        }, function() {
            $(this).find('.caption').slideUp(100);
        });
        
        
        // Apply the transparent backgrounds to captions
        $('div.caption').each(function() {
            bgImage = BASEURL + '/images/transparent/' + $(this).attr('rel') + '.png';
            $(this).css('background-image', 'url(' + bgImage + ')');
        });
        
        $('#featuresReplacement .featuresBlock').hover(function() {
            $(this).find('.caption').slideDown('fast');
        }, function() {
            $(this).find('.caption').slideUp(100);
        });
        
        // Is a member, if not remove the members button
        if(false === ISREGISTERED) {
            $('#menu-members').remove();
        }
        
        currentElement = $('.newsPaginator .navigation li.active').prevAll().length;
        
        page = 0;
        do{
            page++;
        } while (page * 20 < currentElement + 1)
        
        $('.newsPaginator').pajinate({
            'item_container_id' : '.navigation',
            'items_per_page'    : 20,
            'start_page'        : page - 1,
            'num_page_links_to_display' : 5
        });
        
        
        $('#weatherWidget').hover(function(){
            $(this).height('350px');
            $(this).css('borderBottomWidth', '0')
        }, function() {
            $(this).height('38px');
            $(this).css('borderBottomWidth', '2px')
        });
        
    }
    
}


Weather.Auth = {
    
    /**
     * Occurs on domReady
     *
     */
    init: function() {
        
        // Apply focus and blur effects to username
        $('#login_username').focus(function(){
            if($(this).val() == 'Email') {
                $(this).val('');
            } 
        }).blur(function() {
            if($(this).val() == '') {
                $(this).val('Email');
            }
        });
    }
    
}


Weather.Search = {
    
    /**
     * Occurs on domReady
     *
     */
    init: function() {
        
        // Apply focus and blur effects
        $('#searchBox').focus(function(){
            if($(this).val() == 'Search') {
                $(this).val('');
            } 
        }).blur(function() {
            if($(this).val() == '') {
                $(this).val('Search');
            }
        });
    },
    
    
    /**
     * Performs a search
     *
     */
    go: function() {
        // Get the value of the search input
        theQuery = $('#searchBox').serialize();
        
        // Perform the search
        window.location.href = BASEURL + '/search?' + theQuery;
    }
}


$(function() {
    Weather.Main.init();        // Main functions
    Weather.Search.init();      // Search Object
    Weather.Auth.init();        // Auth Object
});


// Break out of iframes
if (top.location!= self.location) {
        top.location = self.location.href
}



/**
 * ----------------------------------------------------------------------------------
 * AutoIframe Heights
 * ----------------------------------------------------------------------------------
 */
function doIframe(){
    o = document.getElementsByTagName('iframe');
    for(i=0;i<o.length;i++){
        if (/\bautoHeight\b/.test(o[i].className)){
            setHeight(o[i]);
            addEvent(o[i],'load', doIframe);
        }
    }
}

function setHeight(e){
    if (e.Document && e.Document.body.scrollHeight) //ie5+ syntax
        e.height = e.contentWindow.document.body.scrollHeight;
    
    else if (e.contentDocument && e.contentDocument.body.scrollHeight) //ns6+ & opera syntax
        e.height = e.contentDocument.body.scrollHeight + 35;
    
    else (e.contentDocument && e.contentDocument.body.offsetHeight) //standards compliant syntax – ie8
        e.height = e.contentDocument.body.offsetHeight + 35;
}

function addEvent(obj, evType, fn){
    if(obj.addEventListener)
    {
        obj.addEventListener(evType, fn,false);
        return true;
    } else if (obj.attachEvent){
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    } else {
        return false;
    }
}

if (document.getElementById && document.createTextNode){
    addEvent(window,'load', doIframe);	
}
