﻿
$(document).ready(function() {

    //Set up delete warning
    $(".deletebutton").live("click", function(){
        javascript: return confirm('Are you sure you want to delete this item?')
        return false;
    });
    
    // Add rollover function to image buttons
    $(".rolloverbutton").mouseover(function() {
        var OverImage = this.src.replace(/(\.[^.]+)$/, 'Over$1');
        this.src = OverImage;
    });

    // Add rollout function to image buttons
    $(".rolloverbutton").mouseout(function() {
        var OverImage = this.src.replace('Over', '');
        this.src = OverImage;
    });
    
    //Set up print
    $(".print").click(function() {
        if (window.print)
            window.print()
        else
            alert("Sorry, your browser doesn't support this feature. Pull down your file menu and select print.");
    });

    // Close window
    $('.closewindow').click(function() {
        window.close()
        return false;
    });

    //Check for tab selector
    var Tab = readCookie('Tab')
    if (Tab) 
    {
        var TabID = readCookie('Tab')
        TabIDArray = TabID.split("_");
        var TabUnique = TabIDArray[0];
        var TabIDNumber = TabIDArray[1];
        ClearTab(TabUnique)
        DisplayTab(TabUnique,TabIDNumber)
    }
    
    //Tab
    $(".tabclick").live("click", function(){

        var TabID = $(this).attr("id");
        TabIDArray = TabID.split("_");
        var TabUnique = TabIDArray[1];
        var TabIDNumber = TabIDArray[2];

        // Remove all formatting
        ClearTab(TabUnique)

        //Display Relevant Tab
        DisplayTab(TabUnique,TabIDNumber)

    });

    

    // initialize tooltip
    $("#ctl00_ContentPlaceHolderMain_datapointin").tooltip({

       // tweak the position
       offset: [210, -40],

       // use the "slide" effect
       effect: 'slide'

    })
    
    //Display event maps
    if ( $(".mapholder").length > 0 ) {   
     
       $('.mapholder').each(function(index) {
       
	   // Find the map div
	   //var map_container = document.getElementById('map_canvas');
        var mapeventid = $(this).attr("id");
        maparray = mapeventid.split("_");
        var eventid = maparray[1];
        var postcode = maparray[2];
           
        var map_container = document.getElementById('map_'+eventid+"_"+postcode);
   
       // Geocode the address
       var geocoder = new google.maps.Geocoder();
       geocoder.geocode({ 'address': postcode}, function(results, status) {
            
            // Set up our map options
            var opts = {
                zoom: 11,
                center: results[0].geometry.location,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            
       
        // Create the map
        var map = new google.maps.Map(map_container, opts);

        // Add the marker
        var marker = new google.maps.Marker({
            position: results[0].geometry.location, 
            map: map
        });
           
        });
        });
    }     
    
    //Process search enter press
    var $btn = $('#ctl00_ImageButtonSearch');
    var $form = $btn.parents('#topbarsearch');

    $form.keypress(function(e){
        if (e.which == 13) 
        {
            if ($btn[0].type == 'image')
                $btn[0].click();
            else
                eval($btn[0].href);
            return false;
        }
    });

    //hide the all of the element with class CollapseContent
    $(".collapsecontent").hide();

    //toggle the componenet with class Open
    $(".open").click(function () {
        $(this).next('.collapsecontent').slideToggle();
        $(this).toggleClass("close");

    });

    //Set up breakout boxes
    $('.breakout').wrapInner('<div class="breakoutmiddle" />');
    $('.breakout').prepend('<div class="breakouttop"></div>');
    $('.breakout').append('<div class="breakoutbottom"></div>');



 });



/****** INTERNAL FUNCTIONS ********/

//Create Cookie
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
//Read cookie
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

//Read URL Parameter
function URLParameter(name) { name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regexS = "[\\?&]" + name + "=([^&#]*)"; var regex = new RegExp(regexS); var results = regex.exec(window.location.href); if (results == null) return ""; else return results[1]; }

//Display tab
function DisplayTab(TabUnique, TabIDNumber) {
    target = document.getElementById('Tab_' + TabUnique + "_" + TabIDNumber);
    if (target)
    {
        target.className = 'contentshow';

        target = document.getElementById('TabImage_' + TabUnique + "_" + TabIDNumber);
        var targetclass = target.className;
        if (targetclass.indexOf("tabsingleline") != -1) {
            target.className = "tabclick tabon tabsingleline";
        }
        else {
            target.className = "tabclick tabon tabmultiline";
        }
        var SelectedTab = TabUnique + "_" + TabIDNumber
        createCookie('Tab',SelectedTab,'1');
    }
}

// Clear Tab Formatting
function ClearTab(TabUnique) {

    $('.tabclick').each(function(index) 
    {
        target = document.getElementById('Tab_' + TabUnique + "_" + (index+1));
        if (target.className == 'contentshow') {
            target.className = 'contenthide';
            target = document.getElementById('TabImage_' + TabUnique + "_" + (index+1));
            var targetclass = target.className;
            if (targetclass.indexOf("tabsingleline") != -1) {
                target.className = "tabclick taboff tabsingleline";
            }
            else {
                target.className = "tabclick taboff tabmultiline";
            }
        }

    })
   
}


/****** EXTERNAL FUNCTIONS ********/

/*
 * jQuery Tools 1.2.5 - The missing UI library for the Web
 * 
 * [tooltip, tooltip.slide, tooltip.dynamic]
 * 
 * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 * 
 * http://flowplayer.org/tools/
 * 
 * File generated: Thu Nov 11 10:15:27 GMT 2010
 */
(function(f){function p(a,b,c){var h=c.relative?a.position().top:a.offset().top,d=c.relative?a.position().left:a.offset().left,i=c.position[0];h-=b.outerHeight()-c.offset[0];d+=a.outerWidth()+c.offset[1];if(/iPad/i.test(navigator.userAgent))h-=f(window).scrollTop();var j=b.outerHeight()+a.outerHeight();if(i=="center")h+=j/2;if(i=="bottom")h+=j;i=c.position[1];a=b.outerWidth()+a.outerWidth();if(i=="center")d-=a/2;if(i=="left")d-=a;return{top:h,left:d}}function u(a,b){var c=this,h=a.add(c),d,i=0,j=
0,m=a.attr("title"),q=a.attr("data-tooltip"),r=o[b.effect],l,s=a.is(":input"),v=s&&a.is(":checkbox, :radio, select, :button, :submit"),t=a.attr("type"),k=b.events[t]||b.events[s?v?"widget":"input":"def"];if(!r)throw'Nonexistent effect "'+b.effect+'"';k=k.split(/,\s*/);if(k.length!=2)throw"Tooltip: bad events configuration for "+t;a.bind(k[0],function(e){clearTimeout(i);if(b.predelay)j=setTimeout(function(){c.show(e)},b.predelay);else c.show(e)}).bind(k[1],function(e){clearTimeout(j);if(b.delay)i=
setTimeout(function(){c.hide(e)},b.delay);else c.hide(e)});if(m&&b.cancelDefault){a.removeAttr("title");a.data("title",m)}f.extend(c,{show:function(e){if(!d){if(q)d=f(q);else if(b.tip)d=f(b.tip).eq(0);else if(m)d=f(b.layout).addClass(b.tipClass).appendTo(document.body).hide().append(m);else{d=a.next();d.length||(d=a.parent().next())}if(!d.length)throw"Cannot find tooltip for "+a;}if(c.isShown())return c;d.stop(true,true);var g=p(a,d,b);b.tip&&d.html(a.data("title"));e=e||f.Event();e.type="onBeforeShow";
h.trigger(e,[g]);if(e.isDefaultPrevented())return c;g=p(a,d,b);d.css({position:"absolute",top:g.top,left:g.left});l=true;r[0].call(c,function(){e.type="onShow";l="full";h.trigger(e)});g=b.events.tooltip.split(/,\s*/);if(!d.data("__set")){d.bind(g[0],function(){clearTimeout(i);clearTimeout(j)});g[1]&&!a.is("input:not(:checkbox, :radio), textarea")&&d.bind(g[1],function(n){n.relatedTarget!=a[0]&&a.trigger(k[1].split(" ")[0])});d.data("__set",true)}return c},hide:function(e){if(!d||!c.isShown())return c;
e=e||f.Event();e.type="onBeforeHide";h.trigger(e);if(!e.isDefaultPrevented()){l=false;o[b.effect][1].call(c,function(){e.type="onHide";h.trigger(e)});return c}},isShown:function(e){return e?l=="full":l},getConf:function(){return b},getTip:function(){return d},getTrigger:function(){return a}});f.each("onHide,onBeforeShow,onShow,onBeforeHide".split(","),function(e,g){f.isFunction(b[g])&&f(c).bind(g,b[g]);c[g]=function(n){n&&f(c).bind(g,n);return c}})}f.tools=f.tools||{version:"1.2.5"};f.tools.tooltip=
{conf:{effect:"toggle",fadeOutSpeed:"fast",predelay:0,delay:30,opacity:1,tip:0,position:["top","center"],offset:[0,0],relative:false,cancelDefault:true,events:{def:"mouseenter,mouseleave",input:"focus,blur",widget:"focus mouseenter,blur mouseleave",tooltip:"mouseenter,mouseleave"},layout:"<div/>",tipClass:"tooltip"},addEffect:function(a,b,c){o[a]=[b,c]}};var o={toggle:[function(a){var b=this.getConf(),c=this.getTip();b=b.opacity;b<1&&c.css({opacity:b});c.show();a.call()},function(a){this.getTip().hide();
a.call()}],fade:[function(a){var b=this.getConf();this.getTip().fadeTo(b.fadeInSpeed,b.opacity,a)},function(a){this.getTip().fadeOut(this.getConf().fadeOutSpeed,a)}]};f.fn.tooltip=function(a){var b=this.data("tooltip");if(b)return b;a=f.extend(true,{},f.tools.tooltip.conf,a);if(typeof a.position=="string")a.position=a.position.split(/,?\s/);this.each(function(){b=new u(f(this),a);f(this).data("tooltip",b)});return a.api?b:this}})(jQuery);
(function(d){var i=d.tools.tooltip;d.extend(i.conf,{direction:"up",bounce:false,slideOffset:10,slideInSpeed:200,slideOutSpeed:200,slideFade:!d.browser.msie});var e={up:["-","top"],down:["+","top"],left:["-","left"],right:["+","left"]};i.addEffect("slide",function(g){var a=this.getConf(),f=this.getTip(),b=a.slideFade?{opacity:a.opacity}:{},c=e[a.direction]||e.up;b[c[1]]=c[0]+"="+a.slideOffset;a.slideFade&&f.css({opacity:0});f.show().animate(b,a.slideInSpeed,g)},function(g){var a=this.getConf(),f=a.slideOffset,
b=a.slideFade?{opacity:0}:{},c=e[a.direction]||e.up,h=""+c[0];if(a.bounce)h=h=="+"?"-":"+";b[c[1]]=h+"="+f;this.getTip().animate(b,a.slideOutSpeed,function(){d(this).hide();g.call()})})})(jQuery);
(function(g){function j(a){var c=g(window),d=c.width()+c.scrollLeft(),h=c.height()+c.scrollTop();return[a.offset().top<=c.scrollTop(),d<=a.offset().left+a.width(),h<=a.offset().top+a.height(),c.scrollLeft()>=a.offset().left]}function k(a){for(var c=a.length;c--;)if(a[c])return false;return true}var i=g.tools.tooltip;i.dynamic={conf:{classNames:"top right bottom left"}};g.fn.dynamic=function(a){if(typeof a=="number")a={speed:a};a=g.extend({},i.dynamic.conf,a);var c=a.classNames.split(/\s/),d;this.each(function(){var h=
g(this).tooltip().onBeforeShow(function(e,f){e=this.getTip();var b=this.getConf();d||(d=[b.position[0],b.position[1],b.offset[0],b.offset[1],g.extend({},b)]);g.extend(b,d[4]);b.position=[d[0],d[1]];b.offset=[d[2],d[3]];e.css({visibility:"hidden",position:"absolute",top:f.top,left:f.left}).show();f=j(e);if(!k(f)){if(f[2]){g.extend(b,a.top);b.position[0]="top";e.addClass(c[0])}if(f[3]){g.extend(b,a.right);b.position[1]="right";e.addClass(c[1])}if(f[0]){g.extend(b,a.bottom);b.position[0]="bottom";e.addClass(c[2])}if(f[1]){g.extend(b,
a.left);b.position[1]="left";e.addClass(c[3])}if(f[0]||f[2])b.offset[0]*=-1;if(f[1]||f[3])b.offset[1]*=-1}e.css({visibility:"visible"}).hide()});h.onBeforeShow(function(){var e=this.getConf();this.getTip();setTimeout(function(){e.position=[d[0],d[1]];e.offset=[d[2],d[3]]},0)});h.onHide(function(){var e=this.getTip();e.removeClass(a.classNames)});ret=h});return a.api?ret:this}})(jQuery);


/*
 *
 * Copyright (c) 2006/2007 Sam Collett (http://www.texotela.co.uk)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * Version 2.0
 * Demo: http://www.texotela.co.uk/code/jquery/newsticker/
 *
 * $LastChangedDate: 2007-05-29 11:31:36 +0100 (Tue, 29 May 2007) $
 * $Rev: 2005 $
 *
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(1($){$.9.D=$.9.g=1(b){b=b||p;i=1(a){j(a);a.4=$("r",a);a.4.q(":o(0)").l().C();a.5=0;h(a)};h=1(a){a.m=t(1(){f(a)},b)};j=1(a){s(a.m)};8=1(a){a.3=7};d=1(a){a.3=c};f=1(a){e(a.3)6;a.3=7;$(a.4[a.5]).n("k",1(){$(2).l();a.5=++a.5%(a.4.B());$(a.4[a.5]).z("k",1(){a.3=c})})};2.y(1(){e(2.x.w()!="A")6;i(2)}).v("g").u(1(){8(2)},1(){d(2)});6 2}})(E);',41,41,'|function|this|pause|items|currentitem|return|true|pauseTicker|fn|||false|resumeTicker|if|doTick|newsticker|startTicker|initTicker|stopTicker|slow|hide|tickfn|fadeOut|eq|4000|not|li|clearInterval|setInterval|hover|addClass|toLowerCase|nodeName|each|fadeIn|ul|size|end|newsTicker|jQuery'.split('|'),0,{}))


