﻿$(document).ready(function () {

    //
    //  LINK DISCLAIMER
    //
        
        $('a').filter(function() { return this.hostname && this.hostname !== location.hostname; })
	          .click(function() {
	          var x = window.confirm('You are about to proceed to an offsite link.  PEPA has no control over the content of this site.  Click OK to proceed.');
	          var val = false;
	          if (x)
	              val = true;
	          else
	              val = false;
	          return val;

	      });
	  
    //
    //  NAVIGATION
    //

        $('ul.navigation').supersubs({ minWidth: 12, maxWidth: 27, extraWidth: 1 })
                                  .superfish({ autoArrows: false, delay: 0, speed: 'fast' });

    //
    //  HEADING REPLACEMENT
    //

        //  TODO: add dot and copyright symbol
        $('h1.title,h2.subtitle').each(function () {
            var title = $.trim($(this).html());
            title = title.replace(/&lt;/gi, "_LT_");
            title = title.replace(/&gt;/gi, "_GT_");
            title = title.replace(/\$/gi, "_DOL_");
            title = title.replace(/&copy;/gi, "_COPY_");
            title = title.replace(/&amp;/gi, "_AMP_");
            title = title.replace(/&nbsp;/gi, " ");
            title = title.replace(/\./gi, "_DOT_");
            title = title.replace(/\+/gi, "_PL_");
            title = title.replace(/\,/gi, "_COM_");
            title = title.replace(/\//gi, "_SL_");
            title = title.replace(/\:/gi, "_COL_");
            title = title.replace(/\;/gi, "_SEM_");
            title = title.replace(/\=/gi, "_EQ_");
            title = title.replace(/\?/gi, "_QU_");
            title = title.replace(/%/gi, "_PER_");
            title = title.replace(/"/gi, "_QUO_");
            title = title.replace(/\@/gi, "_AT_");
            title = title.replace(/\\/gi, "_BS_");
            var img = $('<img>');
            img.attr('src', 'http://' + document.domain + '/images/' + $(this).attr('class') + '/' + escape(title) + '.aspx');
            img.attr('alt', title);
            $(this).html('');
            $(this).append(img);
        });
        
    //
    //  SEARCH BOX
    //

        //  clears e-news text
        $('.search_field').focus(function() {
            if ($(this).val() == 'Search') {
                $(this).val('');
                $(this).addClass('search_field_active');
            }
        }).blur(function() {
            if ($(this).val() == '') {
                $(this).val('Search');
                $(this).removeClass('search_field_active');
            }
       
        });
    //
    //  HEADER IMAGES
    //

        //  don't run slider on header images
       // if (!$.browser.msie && parseInt($.browser.version, 10) != 6) {

            if (!$('#aspnetForm').hasClass('template_homepage'))
            {

                //
                //  MAIN
                //

                    //  header images
                    $('.header_images').cycle({
                        fx: 'scrollLeft',
                        speed: 2500,
                        timeout: 5000,
                        easing: 'swing',
                        random: 1
                    });

            } 
            else
            {

                //
                //  HOMEPAGE
                //

                    $('.header_slideshow ul').cycle({
                        fx: 'scrollLeft',
                        speed: 2500,
                        timeout: 5000,
                        easing: 'swing',
                        random: 0,
                        fastOnEvent: 1000,
                        pager: '#header_images_pager',
                        next: '.header_images_next',
                        prev: '.header_images_previous',
                        after: function() {


                        }
                    });

                   

            }

      //  } 
      //  else 
      //  {

            //  copy description of first slide on ie6
      //      $('.header_image_description').html($('.header_images ul').find('.description').first().html());

      //  }


    //
    //  HOVER CLASS
    //

        $('.hover').hover(function () { $(this).addClass('hover_active') },
                          function () { $(this).removeClass('hover_active') });

        $('.read_more').hover(function () { $(this).find('img').attr('src', '/_sites/pepa/_media/images/read_more_hover.png'); },
                              function () { $(this).find('img').attr('src', '/_sites/pepa/_media/images/read_more.png'); });

        $('.search_button').hover(function() { $(this).attr('src', '/_sites/pepa/_media/images/search_button_hover.png'); },
                                  function() { $(this).attr('src', '/_sites/pepa/_media/images/search_button.png'); });
        


});

