﻿     $(function(){
        //set the text replacement on inside page    
        Cufon.set('fontFamily', 'Stag').replace('div#banner #site-tools ul li a')('div.left div h3')('div.right h3');
        
        if($('body').attr('id') == 'inside'){
            Cufon.set('fontFamily', 'Stag').replace('div.right h1')('div.right h2')('div.right h3');
            Cufon.set('fontFamily', 'StagMedium').replace('div#copy ul.news li span.title a',{hover:true});
        }
        //set the text replacement and initialise the tab control on the homepage
        else{
            $("#tabs").tabs();
            Cufon.set('fontFamily', 'StagMedium').replace('#tabs li a',{hover:true});
            Cufon.set('fontFamily', 'HelveticaNeue').replace('div#presentation h1')('div#presentation h2')('div#presentation .bottom');
            Cufon.set('fontFamily', 'HelveticaNeue').replace('#presentation .left a',{hover:true});
        }
        //add first class to top LNS item
        $('body#inside #content .left ul li:first-child').addClass('first');
        //is there a selected LNS item?
        var selectedLNS = $('#content .left > ul > li.on');
        //then remove the bottom border of the previous link
        if(selectedLNS != null){
            $(selectedLNS).prev().css('background','none')
            $(selectedLNS).prev().find('a').css('padding-bottom','10px')
        }
        //we wrap content list items in a span tag to differentiate the text colour from the bullet colour in the CSS
        $('#copy ul').each(function(){
            if(!$(this).attr('class')){
                $(this).find('li').each(function(){
                    $(this).html('<span>' + $(this).html() + '</span>');
                })
            }
        })

        $('p').each(function(){
            if($(this).attr('align') != 'undefined' && $(this).attr('align') != false && $(this).attr('align') != ''){
                $(this).wrap('<div class="pic pic' + $(this).attr('align') + '" style="width:' + $(this).find('img').attr('width') + 'px"/>');
                $(this).append('<span>' + $(this).find('img').attr('alt') + '</span>');
                
            }
        })

        
        $('#copy ol').each(function(){
            if(!$(this).attr('class')){
                $(this).find('li').each(function(){
                    $(this).html('<span>' + $(this).html() + '</span>');
                })
            }
        })
        
        $('#copy table tr').each(function(){
            $(this).find('td').each(function(){
                $(this).html('<span>' + $(this).html() + '</span>');
            })
        })
        
        $('#copy table td:last-child').addClass('last');
        $('#copy table tr:last-child').addClass('last');
        $('#site-tools ul li:last-child').addClass('last');
        
        
        //news pagingation rollovers
        $('#pagination li a').mouseover(function(){$(this).parent('li').addClass('on')})
        $('#pagination li a').mouseout(function(){$(this).parent('li').removeClass('on')})
        //footer link rollovers
        $('div#footer div ul li a').mouseover(function(){$(this).parent('li').addClass('on')})
        $('div#footer div ul li a').mouseout(function(){$(this).parent('li').removeClass('on')})

        $('#tabs li a').click(function(){Cufon.set('fontFamily', 'StagMedium').replace('#tabs li a',{hover:true})})
        
        $('#content .right #copy a, #SponsorLink').each(function(){
            if($(this).attr('href').indexOf("http://") != -1 && $(this).attr('href').indexOf("anpost.ie") == -1)
                $(this).addClass('ext');
        })
        
        $('#content #rhsWrapper #stages-listings ul li').each(function(){
            $(this).click(function(){
               var directTo = $(this).find('a').attr('href'); 
               location.href = directTo
            })
        })
    })
    
    function clearfield(val, objID){
        if($('input#' + objID).val() == val)
            $('input#' + objID).val('');
    }
    
    function emailme() {
        var title = document.title;
        var url = document.location.href;
        var subject = "An Post Rás";
        var bodyText = "I saw this page and thought you might like to see it " + url;

        window.location.href = "mailto:?subject=" + subject + "&body=" + bodyText;

    }
    
    function fb_share()
    {
		var title = document.title;
        var url = document.location.href;
		window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url) + '&t=' + encodeURIComponent("An Post Rás - " + title), 'sharer','toolbar=0,status=0,width=626,height=436');
		return false;
    }
    function t_share()
    {
		var title = document.title;
        var url = document.location.href;
		window.open('http://twitter.com/share?text=' + encodeURIComponent("An Post Rás - " + title), 'sharer','toolbar=0,status=0,width=626,height=436');
		return false;
    }

