jQuery( function( $ ) {
    
    // stupid reset search boxes
    $('#Country').val('Australia').select();
    $('#CityFrom').val('Sydney').select();
    
    // add external link attribute to links
    $('.ebay a').attr('target','_blank');
    
    // ------ START SHOW LINK LIST BOXES ------ //
    
      $(".mod_linklist:has(p),.mod_linklist:has(ul)").each(function(){
          $(this).css('display','block');
      });
    
    // ------ END SHOW LINK LIST BOXES ------ //
    
    
    // ------ START ROUNDED CORNERS FOR HEADINGS AND BOXES ------ //
            
        // add the rounded corners to headings
        $( 'h1,h3,#navTabs,#navTabs li a' ).not($('#search-scroll .mod_rss_ticker h3')).each( function(){
            
            // Yellow corners are the default for most headings
            var tab_tl_img = 'http://dev-web.ebaydevelopment.co.uk/cssyukontoolbox/img/yellow_tl.gif';
            var tab_tr_img = 'http://dev-web.ebaydevelopment.co.uk/cssyukontoolbox/img/yellow_tr.gif';
            
            // If this heading is inside the popular city box, the tab outlines need to be grey
            if($( this ).is( 'a' ))
            {
                var tab_tl_img = 'http://dev-web.ebaydevelopment.co.uk/cssyukontoolbox/img/grey_tl.gif';
                var tab_tr_img = 'http://dev-web.ebaydevelopment.co.uk/cssyukontoolbox/img/grey_tr.gif';
            }
                        
            // spans to contain the curvey corner graphics
            var span_tl = $( '<span><img src="' + tab_tl_img + '" /></span>' ).css( 'position', 'absolute' );
            var span_tr = $( '<span><img src="' + tab_tr_img + '" /></span>' ).css( 'position', 'absolute' );
                
             // determine the positioning for the curvey corners
            var tl_css = { top: -1, left: -1 };
            var tr_css = { top: -1, right: -1 };
            
            // Internet Explorer still hasn't fixed their box model completely so we still need to do this hackaround
            if( $.browser.msie && !$( this ).parent().is( '.mod_linklist' ) && !$( this ).is( 'a' ) && !$( this ).is( '#navTabs' ) ) {
                // IE 7 - because it's still not quite good enough yet
                if( $.browser.version.indexOf( '7.' ) == 0 ) {
                    tl_css = { top: 1, left: -1 };
                    tr_css = { top: 1, right: -1 };
                }
                // IE 6 - because some people just do not seem to want to give it up
                else if ( $.browser.version.indexOf( '6.' ) == 0 ) {
                    tl_css = { top: 2, left: -19 };
                    tr_css = { top: 2, left: ( $(this).width() - 9 ) + 'px' };
                }
            };
            if( $.browser.version.indexOf( '6.' ) == 0 && $( this ).is( 'a' ) )
            {
                var tr_css = { top: -1, right: -2 };
            }
            if( $.browser.version.indexOf( '6.' ) == 0 && $( this ).is( '#navTabs' ) )
            {
                var tl_css = { top: 0, left: -1 };
                var tr_css = { top: 0, right: -1 };
            }
            // add the styles to the corners and add to the page
            span_tl.css( tl_css ).appendTo( this );
            span_tr.css( tr_css ).appendTo( this );
            
        });
    
    // ------ END ROUNDED CORNERS FOR HEADINGS AND BOXES ------ //
    
    // ------ START MENU HOVER FOR DROP DOWNS ------ //
        var menu_hover_timer;
        $( '#navigation .mod_nav.alt ul li').hover( function(){
            $(this).find('ul').fadeIn('');
        },
        function(){
            $(this).find('ul').fadeOut('');
        });
        
    // ------ END MENU HOVER FOR DROP DOWNS ------ //
    
        
    // ------ START CLICK HANDLING FOR HOMEPAGE MAP TABS ------ //
    
      $("#navTabs a").click(function(){
          var $this = this;
          $("#navTabs li").removeClass('active');
          $(this).parent().addClass('active');
          $('#map-container .navMap:not(:hidden)').find('a').hide().end().fadeOut(300, function(){
              $('#nm' + $($this).attr('href').replace('#nt','') ).fadeIn(300, function(){
                  $('#nm' + $($this).attr('href').replace('#nt','')).find('a').show();
                  // damn internet explorer - this makes sure the font rendering is smooth in IE after the fade transistions
                  if(jQuery.browser.msie)
                  {
                      $('#nm' + $($this).attr('href').replace('#nt','')).each(function(){
                          this.style.removeAttribute('filter');
                      });
                  }
              });
          });
          return false;
      });
      var preselected_tab = document.location.href.match('#([^?]+)');
      if(preselected_tab) $('a[href=#' + preselected_tab[1] + ']').click();
    // ------ END CLICK HANDLING FOR HOMEPAGE MAP TABS ------ //
    
    // ------ START ROTATING HOMEPAGE POSTCARDS ------ //
      if ($("#homepage-collage").html()){
          var current_postcard = 1;
          var postcards = {
              1 : $("#homepage-collage img").attr('src'),
              2 : '/assets/images/loh_hp_concept_map_tabs_polariod2.jpg',
              3: '/assets/images/loh_hp_concept_map_tabs_polariod3.jpg'
          };
          setInterval(function(){
              current_postcard = current_postcard < 3 ? current_postcard + 1 : 1;
              $("#homepage-collage img")
                  .fadeOut(1000, function(){
                      $(this).attr('src',postcards[current_postcard]);
                      $(this).fadeIn(1000);
                  });
          },8000);
      };
    // ------ END ROTATING HOMEPAGE POSTCARDS ------ //
    
    // ------ START HOVER EFFECT FOR SEARCH BUTTONS ------ //
    
        $( 'input.search').hover( function(){
            $( this ).attr( 'src', '/assets/images/button_search_hover.gif' );
        },
        function(){
            $( this ).attr( 'src', '/assets/images/button_search.gif' );
        });
        
    // ------ END HOVER EFFECT FOR SEARCH BUTTONS ------ //
    
    // ------ START AUTO LIST POPULATION FOR LARGE SEARCH BOXES ------ //
        
        // add the listeners and handlers for changing the options in boxes as country/city selections are made
        $('#Country')
            .change(function(){
                $('#CityFrom option').remove();
                $.getJSON("/standalone/ajax/?action=getCities&country=" + escape( $(this).val()),
                function(data){
                  $.each(data.countries, function(i,item){
                    $('#CityFrom').append('<option value="' + item + '">' + item + '</option>');
                  });
                  $('#CityFrom').change();
                });
                $(this).hide().show(); // HACK FOR IE7
            });
            
        // add the listeners and handlers for changing the options in boxes as country/city selections are made
        $('#CityFrom')
            .change(function(){
                $('#LocationFrom').html('<option value="">All Locations</option>');
                $(this).hide().show();
                // we only populate the loction drop down for AU and NZ
                if($('#Country').val()=='Australia'||$('#Country').val()=='New Zealand'||$_get('use_full_destination_list'))
                {
                    $('#LocationFrom,#LocationFrom option').css('color','#000');
                    $('body.level2 #LocationFrom,body.level2 #LocationFrom option').css('color','#333');
                    $.getJSON("/standalone/ajax/?action=getLocations&country=" + escape( $('#Country').val()) + "&cityname=" + escape( $(this).val() ),
                    function(data){
                      $.each(data.locations, function(i,item){
                        $('#LocationFrom').append('<option value="' + item + '">' + item + '</option>');
                        $('#LocationFrom').hide().show(); // HACK FOR IE7
                      });
                    });
                    $(this).hide().show(); // HACK FOR IE7
                }
                else
                {
                    $('#LocationFrom,#LocationFrom option').css('color','#ccc');
                }
            });
        
    // ------ END AUTO LIST POPULATION FOR LARGE SEARCH BOXES ------ //
    
    
    // ------ START LIGHTBOX HANDLING FOR MAIN HOTEL PAGE LISTINGS ------ //
    
        // add the date selector stylesheet
        $( 'body.level2 div.hotel-specials a.lightbox, div.navMap a' )
            .click( function(){
                var click_url = $(this).attr('href');
                var query = click_url.substring(click_url.indexOf('?') + 1) + '&';
                tb_show( 'Hotel Search', '/standalone/hotel-bookings/?' + query + 'KeepThis=true&TB_iframe=true&height=320&width=370' );
                return false;
            });
    
    // ------ END LIGHTBOX HANDLING FOR MAIN HOTEL PAGE LISTINGS ------ //
    
    // ------ START PREPOPULATION HANDLING FOR LIGHTBOX SEARCH FORM ------ //
    
        if($( 'body.blank' ).html())
        {
            if( $_get('HotelName') )
            {
                $('input[name=HotelName]').val($_get('HotelName'));
                $('#HotelName').text($_get('HotelName'));
            }
            else if( $_get('CityFrom') && !$_get('HotelId') )
            {
                $('label[for=label]').text('City');
                $('#HotelName').text($_get('CityFrom'));
            }
            if( $_get('HotelId') )
            {
                $('input[name=HotelId]').val($_get('HotelId'));
            }
            if( $_get('CityFrom') )
            {
                $('input[name=CityFrom]').val($_get('CityFrom'));
            }
        }
    
    // ------ END PREPOPULATION HANDLING FOR LIGHTBOX SEARCH FORM ------ //
    
    // ------ START BUILDING SEND TO A FRIEND LINK ------ //
    
      if ($('.tellafriend a.friend')) {
        var pageurl = encodeURI(Base64.encode(document.location.href));
        pageurl = "/standalone/tell-a-friend/?url=" + pageurl + "&amp;KeepThis=true&amp;TB_iframe=true&amp;height=340&amp;width=630";
        $('.tellafriend a.friend').attr("href",pageurl);
      }
      
      // and decodeing it again
      if ($('#referafriend input#url')) {
        var pageurl = decodeURI(Base64.decode($_get('url')));
        $('#referafriend input#url').val(pageurl);
      }
    
    // ------ START BUILDING SEND TO A FRIEND LINK ------ //
    
    // ------ START DESTINATION SEARCH NAV SELECT BOXES ------ //
    
        $('#destination_search_state,#destination_search_region').change(function(){
            document.location.href = $(this).val();
        });
    
    // ------ END DESTINATION SEARCH NAV SELECT BOXES ------ //
    
    // ------ START ADD STYLING HOOKS TO TABLES WITHIN CONTENT AREAS ------ //
    
        $('#main .mod_content table tr:even:not(:eq(0))').addClass('odd');
        $('#main .mod_content table tr td:first-child').addClass('first-column');
    
    // ------ END ADD STYLING HOOKS TO TABLES WITHIN CONTENT AREAS ------ //
    
    // ------ START TAB AND VISIBILITY HANDLING FOR TRAVEL PAGE LAYOUTS------ //
    
        if($( 'body.travel' ).html())
        {
            // we only need to do any of this if any extra tabs exist
            if($('#images').html() || $('#things-to-do').html() || $('#weather').html())
            {
                // set a min height for the default visible container
                $('#main-inner .mod_content:eq(0)').css('min-height','649px');
                
                // ie 6 doesnt understand min-height above, so we do a little jquery magic instead
                if($.browser.msie && $.browser.version.indexOf( '6.' ) == 0)
                {
                    $('#main-inner .mod_content:eq(0)').height() < 511 ? $('#main-inner .mod_content:eq(0)').height(511) : null;
                }
                
                // hide each section that exists on this page and create a tab for it
                var tabs = new Array();
                
                $('#images,#things-to-do,#weather')
                    .hide()
                    .css('min-height','649px')
                    .each(function(i){
                       tabs[i] = new Array($(this).attr('id'),$('h2,h3', this).text());
                        // ie 6 doesnt understand min-height above, so we do a little jquery magic instead
                        if($.browser.msie && $.browser.version.indexOf( '6.' ) == 0)
                        {
                            $(this).height() < 511 ? $(this).height(511) : null;
                        }
                    });
                
                // add the overview link to the start of the tab list
                tabs.unshift(new Array('main-inner .mod_content:eq(0), #main-inner .mod_images:eq(0)','Overview'));
                
                // build the tab menu and add to the page
                var tab_menu = $('<ul class="tab-menu"></ul>').prependTo('#main-inner');
                $.each(tabs,function(){
                    $('<li><a href="#">' + this[1] + '</a></li>')
                        .click(function(){
                            $(this).parent().find('a').css('text-decoration','underline');
                            $(this).find('a').css('text-decoration','none');
                            $('#main-inner .mod_content:eq(0),#main-inner .mod_images:eq(0),#images,#things-to-do,#weather').hide();
                            $('#'+$(this).data('container').toString()).show();
                            return false;
                        })
                        .data('container',this[0])
                        .appendTo(tab_menu);
                });
                // remove the underline from the first link
                $('li:first-child a', tab_menu).css('text-decoration','none');
                $('li:last-child', tab_menu).addClass('last');
            }
            
        }
    
    // ------ END TAB AND VISIBILITY HANDLING FOR TRAVEL PAGE LAYOUTS------ //
    
    // ------ START ALERT SUBSCRIPTION FORM EMAIL PREPOPULATION AND CLEARING ------ //
    
      var hint = "Enter your email address";
      if ($("#alerts")){
        var e = $_get( 'email' );
        e = e.indexOf('@')>-1 ? $_get( 'email' ) : hint;
        $('#subscribe_email').val(e);
      }
      
      $('#subscribe_email').focus(function(){
        var t = jQuery(this);
        if(t.val()==hint) t.val('');
      }).blur(function(){
        var t = jQuery(this);
        if(t.val()=='') t.val(hint);
      });
 
    // ------ END  ALERT SUBSCRIPTION FORM EMAIL PREPOPULATION AND CLEARING ------ //
      
    // ------ START ADD VALIDATION SCRIPTS TO FORM PAGES ------ //
    
      if ($("body#alerts") || $("body#unsubscribe")) {
        $.getScript( "/lib/js/amp11/formValidation_1_0.js");
      }
    
    // ------ START ADD VALIDATION SCRIPTS TO FORM PAGES ------ //
    
    // ------ START HANDLING OF CLICKS FOR LINKS TO EXTERNAL HELP RESOURCES ------ //
    
      $('#navigation .mod_nav.alt a').click(function(){
          var href = $(this).attr('href');
          if(href.indexOf('www.faq-central.com')>0 || href.indexOf('console.startcorp.com')>0)
          {
              winPop( $(this).attr('href'), 750, 500, 1, 5, 5);
              return false;
          }

      });
    
    // ------ END HANDLING OF CLICKS FOR LINKS TO EXTERNAL HELP RESOURCES ------ //
    
    // ------ START FAQ SLIDING CONTENT ------ //
    
      $(function() {
      	$(".faqs dd").hide();
      	$(".faqs dt").css("cursor","pointer");
      	$(".faqs dt").bind("click", function() {
      		var qaid = $(this).attr("id");
      		qaid = qaid.replace("_q_", "_a_");
      		$(".faqs dd:not([@id="+qaid+"])").fadeOut();
      		$("#" + qaid).slideToggle('slow');
      	});
      });
      
    // ------ END FAQ SLIDING CONTENT ------ //
    
    // ------ START SEARCH FORM STAR RATING CONVERSION ------ //
    
      $('#search form, .hotel-search-narrow form').submit(function(){
        var stars = new Array();
        $('input[name=StarRating]:checked').each(function(i){
          stars[i] = ($(this).val());
        });
        stars.sort();
        stars = stars.join();
        document.getElementById('HotelStarRating').value = stars;
        // uncheck the star boxes so they don't get sent as well
        $('input[name=StarRating]').each(function(i){
          this.checked = false;
        });
      });
    
    // ------ END SEARCH FORM STAR RATING CONVERSION ------ //
    
    // ------ START ONLINE ANSWERS HANDLING ------ //
    
	$( '#frmOnlineAnswers' ).submit( function(){
		window.open('', 'answerWindow', 'toolbar=1,resizable=1,scrollbars=1,left=50,top=50,width=630,height=540');
        $('#oa_question').val("LOH: " + $('#oa_question').val());
		$(this).attr("target", "answerWindow");
        setTimeout("$('#oa_question').val($('#oa_question').val().replace('LOH: ', ''));", 500);
	});
    
    // ------ END ONLINE ANSWERS HANDLING ------ //
    
    // ------ START PREPOPULATE HOMEPAGE SEARCH ------ //
    if($_get('Country')&&$_get('CityFrom'))
    {
        $('#Country').val($_get('Country')).change();
        setTimeout(function(){
            $('#CityFrom').val($_get('CityFrom')).change();
        },900);
    }
    // ------ END PREPOPULATE HOMEPAGE SEARCH ------ //
    
    
    // ------ START PREPOPULATE SECOND LEVEL SEARCH BOX WITH RELEVANT CITY ------ //
    
    /* this function does its best to prepopulate the city in the hotel search by using the url, the destination search box and
     * the json cities below. You can force it to find a match by adding items to the "locations" json object
     */
	if(document.location.href.indexOf('city-reviews') > 0 && document.location.href.match('city-reviews/(.*)/'))
    {
        var locations = {
            'act' : 'Canberra', 'northern-territory' : 'Darwin', 'nsw': 'Sydney', 'queensland' : 'Brisbane',
            'south-australia' : 'Adelaide', 'tasmania' : 'Hobart', 'victoria': 'Melbourne', 'western-australia': 'Perth',
            'tropical-north' : 'Cairns'
        }
        var url_location = document.location.href.match('city-reviews/(.*)/')[1];
        var location_name_from_url = titleCaps(url_location.replace('-', ' '));
        
        // If theres a direct match from the url to the json, then thats our winner
        if(locations[url_location])
        {
            $('#CityFrom').val(locations[url_location]).change();
        }
        
        // See if theres a match of the url directly in the select list
        else if($('#CityFrom option[value="' + location_name_from_url + '"]').length > 0)
        {
            $('#CityFrom').val(location_name_from_url).change();
        }
        
        // Still no match so try and get the location from the "Destination Search" box under the main search box
        else
        {
            var location_state = $('#destination_search_state option:selected').text().toLowerCase().replace(' ' ,'-');
            var location_region = $('#destination_search_region option:selected').text();
            if($('#CityFrom option[value="' + location_region + '"]').length > 0)
            {
                $('#CityFrom').val(location_region).change();
            }
            else if(locations[location_state])
            {
                $('#CityFrom').val(locations[location_state]).change();
            }
        }
    }
    
    // ------ END PREPOPULATE SECOND LEVEL SEARCH BOX WITH RELEVANT CITY ------ //
    
    
    // ------ START TIP HELP TEXT FOR HOMEPAGE TABS ------ //
    $('#tab-tip').hover(function(){
        $('span.message', this).slideDown(200);
    },function(){
        $('span.message', this).slideUp(200);
    });
    // ------ END TIP HELP TEXT FOR HOMEPAGE TABS ------ //
    
    
    // ------ START Open SSH links in target=_top ------- //
    
    $.each( $('a[href$="https://securehsa.lotsofhotels.com.au/WebjetTSA/home.aspx?EntryPoint=Profile"], a[href$="https://securehsa.lotsofhotels.com.au/WebjetTSA/home.aspx?EntryPoint=TripVault"], a[href$="https://securehsa.lotsofhotels.com.au/WebjetTSA/home.aspx?EntryPoint=ProfileCC"]'), function() {
    	$(this).attr("target", "_top");
    });
    
    // ------ END Open SSH links in target=_top ------- //
    
});

// ------ START REPOSITION TABBED CONTENT EDITOR LINKS ------ //

$(window).load(function(){    
    var divids = "mod_linklist_8,mod_linklist_9";
    
    if (typeof( window[ 'pageid' ] ) != "undefined" && pageid > 0 && divids != "") {
      // modify the editor button positions
      if ($('#mod_linklist_8_ctrl').html() || $('#mod_linklist_9_ctrl').html()) {
        var dividarr = divids.split(",");
        // get the starting control position
        var off = $("#" + dividarr[0] + "_ctrl").offset();
        // loop through the divids and shift their offset
        var lplus = 110;
        for(var i=1;i<divids.length;i++) {
          $("#" + dividarr[i] + "_ctrl").css({
            left: (off.left + (i*lplus) + 'px'),
            top: (off.top + 'px')
          });
        }
      }
    }
})    
    // ------ END REPOSITION TABBED CONTENT EDITOR LINKS ------ //

function $_get( key ) {
	var sReturn = "";
  var replaceThis = "\+";
	q_string = location.search.substring( 1 ).split( "&" );
	q_array = new Array();
   for( i=0; i < q_string.length; i++ ) {
	  pair = q_string[ i ].split( "=" );
	  if ( key == pair[ 0 ].toString() )
			sReturn = unescape( pair[ 1 ] ).toString();
      sReturn = sReturn.replace(/\+/g,' ')
   } 	
   return sReturn;
}

function winPop( url, width, height, scrollable, left, top) {
	
		if ( scrollable && ( scrollable == 1 || scrollable == "true" ) )	
				scrollit = 1;
		else		
				scrollit = 0;
				
		if ( !width ) {
				width = 350;
		}
		
		if ( !height ) {
				height = 250;
		}
		
		if ( !left ) {
				left = 20;
		}
		
		if ( !top ) {
				top = 20;
		}
	
		window.open(url, 'pop', 'toolbar=0,resizable=1,scrollbars=' + scrollit + ',left=' + left + ',top=' + top + ',width=' + width + ',height=' + height);
	
}

/**
*
*  Base64 encode / decode
*  http://www.webtoolkit.info/
*
**/

var Base64 = {

	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;

		input = Base64._utf8_encode(input);

		while (i < input.length) {

			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);

			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;

			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}

			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

		}

		return output;
	},

	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		while (i < input.length) {

			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(chr1);

			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}

		}

		output = Base64._utf8_decode(output);

		return output;

	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

};

/*
 * Title Caps
 * 
 * Ported to JavaScript By John Resig - http://ejohn.org/ - 21 May 2008
 * Original by John Gruber - http://daringfireball.net/ - 10 May 2008
 * License: http://www.opensource.org/licenses/mit-license.php
 */

(function(){
	var small = "(a|an|and|as|at|but|by|en|for|if|in|of|on|or|the|to|v[.]?|via|vs[.]?)";
	var punct = "([!\"#$%&'()*+,./:;<=>?@[\\\\\\]^_`{|}~-]*)";
  
	this.titleCaps = function(title){
		var parts = [], split = /[:.;?!] |(?: |^)["Ò]/g, index = 0;
		
		while (true) {
			var m = split.exec(title);

			parts.push( title.substring(index, m ? m.index : title.length)
				.replace(/\b([A-Za-z][a-z.'Õ]*)\b/g, function(all){
					return /[A-Za-z]\.[A-Za-z]/.test(all) ? all : upper(all);
				})
				.replace(RegExp("\\b" + small + "\\b", "ig"), lower)
				.replace(RegExp("^" + punct + small + "\\b", "ig"), function(all, punct, word){
					return punct + upper(word);
				})
				.replace(RegExp("\\b" + small + punct + "$", "ig"), upper));
			
			index = split.lastIndex;
			
			if ( m ) parts.push( m[0] );
			else break;
		}
		
		return parts.join("").replace(/ V(s?)\. /ig, " v$1. ")
			.replace(/(['Õ])S\b/ig, "$1s")
			.replace(/\b(AT&T|Q&A)\b/ig, function(all){
				return all.toUpperCase();
			});
	};
    
	function lower(word){
		return word.toLowerCase();
	}
    
	function upper(word){
	  return word.substr(0,1).toUpperCase() + word.substr(1);
	}
})();

/*
 * Thickbox 3 - One Box To Rule Them All.
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2007 cody lindley
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/
var _base = $( 'base' ).attr( 'href' );
var tb_pathToImage = ( _base ? _base : '' ) + "/lib/images/loadingAnimation.gif";
jQuery( 'head' ).append( '<link rel="stylesheet" href="' + ( _base ? _base : '' ) + '/lib/css/jquery/thickbox.css"></script>' ); 
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}('$(o).2S(9(){1u(\'a.18, 3n.18, 3i.18\');1w=1p 1t();1w.L=2H});9 1u(b){$(b).s(9(){6 t=X.Q||X.1v||M;6 a=X.u||X.23;6 g=X.1N||P;19(t,a,g);X.2E();H P})}9 19(d,f,g){3m{3(2t o.v.J.2i==="2g"){$("v","11").r({A:"28%",z:"28%"});$("11").r("22","2Z");3(o.1Y("1F")===M){$("v").q("<U 5=\'1F\'></U><4 5=\'B\'></4><4 5=\'8\'></4>");$("#B").s(G)}}n{3(o.1Y("B")===M){$("v").q("<4 5=\'B\'></4><4 5=\'8\'></4>");$("#B").s(G)}}3(1K()){$("#B").1J("2B")}n{$("#B").1J("2z")}3(d===M){d=""}$("v").q("<4 5=\'K\'><1I L=\'"+1w.L+"\' /></4>");$(\'#K\').2y();6 h;3(f.O("?")!==-1){h=f.3l(0,f.O("?"))}n{h=f}6 i=/\\.2s$|\\.2q$|\\.2m$|\\.2l$|\\.2k$/;6 j=h.1C().2h(i);3(j==\'.2s\'||j==\'.2q\'||j==\'.2m\'||j==\'.2l\'||j==\'.2k\'){1D="";1G="";14="";1z="";1x="";R="";1n="";1r=P;3(g){E=$("a[@1N="+g+"]").36();25(D=0;((D<E.1c)&&(R===""));D++){6 k=E[D].u.1C().2h(i);3(!(E[D].u==f)){3(1r){1z=E[D].Q;1x=E[D].u;R="<1e 5=\'1X\'>&1d;&1d;<a u=\'#\'>2T &2R;</a></1e>"}n{1D=E[D].Q;1G=E[D].u;14="<1e 5=\'1U\'>&1d;&1d;<a u=\'#\'>&2O; 2N</a></1e>"}}n{1r=1b;1n="1t "+(D+1)+" 2L "+(E.1c)}}}S=1p 1t();S.1g=9(){S.1g=M;6 a=2x();6 x=a[0]-1M;6 y=a[1]-1M;6 b=S.z;6 c=S.A;3(b>x){c=c*(x/b);b=x;3(c>y){b=b*(y/c);c=y}}n 3(c>y){b=b*(y/c);c=y;3(b>x){c=c*(x/b);b=x}}13=b+30;1a=c+2G;$("#8").q("<a u=\'\' 5=\'1L\' Q=\'1o\'><1I 5=\'2F\' L=\'"+f+"\' z=\'"+b+"\' A=\'"+c+"\' 23=\'"+d+"\'/></a>"+"<4 5=\'2D\'>"+d+"<4 5=\'2C\'>"+1n+14+R+"</4></4><4 5=\'2A\'><a u=\'#\' 5=\'Z\' Q=\'1o\'>1l</a> 1k 1j 1s</4>");$("#Z").s(G);3(!(14==="")){9 12(){3($(o).N("s",12)){$(o).N("s",12)}$("#8").C();$("v").q("<4 5=\'8\'></4>");19(1D,1G,g);H P}$("#1U").s(12)}3(!(R==="")){9 1i(){$("#8").C();$("v").q("<4 5=\'8\'></4>");19(1z,1x,g);H P}$("#1X").s(1i)}o.1h=9(e){3(e==M){I=2w.2v}n{I=e.2u}3(I==27){G()}n 3(I==3k){3(!(R=="")){o.1h="";1i()}}n 3(I==3j){3(!(14=="")){o.1h="";12()}}};16();$("#K").C();$("#1L").s(G);$("#8").r({Y:"T"})};S.L=f}n{6 l=f.2r(/^[^\\?]+\\??/,\'\');6 m=2p(l);13=(m[\'z\']*1)+30||3h;1a=(m[\'A\']*1)+3g||3f;W=13-30;V=1a-3e;3(f.O(\'2j\')!=-1){1E=f.1B(\'3d\');$("#15").C();3(m[\'1A\']!="1b"){$("#8").q("<4 5=\'2f\'><4 5=\'1H\'>"+d+"</4><4 5=\'2e\'><a u=\'#\' 5=\'Z\' Q=\'1o\'>1l</a> 1k 1j 1s</4></4><U 1W=\'0\' 2d=\'0\' L=\'"+1E[0]+"\' 5=\'15\' 1v=\'15"+1f.2c(1f.1y()*2b)+"\' 1g=\'1m()\' J=\'z:"+(W+29)+"p;A:"+(V+17)+"p;\' > </U>")}n{$("#B").N();$("#8").q("<U 1W=\'0\' 2d=\'0\' L=\'"+1E[0]+"\' 5=\'15\' 1v=\'15"+1f.2c(1f.1y()*2b)+"\' 1g=\'1m()\' J=\'z:"+(W+29)+"p;A:"+(V+17)+"p;\'> </U>")}}n{3($("#8").r("Y")!="T"){3(m[\'1A\']!="1b"){$("#8").q("<4 5=\'2f\'><4 5=\'1H\'>"+d+"</4><4 5=\'2e\'><a u=\'#\' 5=\'Z\'>1l</a> 1k 1j 1s</4></4><4 5=\'F\' J=\'z:"+W+"p;A:"+V+"p\'></4>")}n{$("#B").N();$("#8").q("<4 5=\'F\' 3c=\'3b\' J=\'z:"+W+"p;A:"+V+"p;\'></4>")}}n{$("#F")[0].J.z=W+"p";$("#F")[0].J.A=V+"p";$("#F")[0].3a=0;$("#1H").11(d)}}$("#Z").s(G);3(f.O(\'37\')!=-1){$("#F").q($(\'#\'+m[\'26\']).1T());$("#8").24(9(){$(\'#\'+m[\'26\']).q($("#F").1T())});16();$("#K").C();$("#8").r({Y:"T"})}n 3(f.O(\'2j\')!=-1){16();3($.1q.35){$("#K").C();$("#8").r({Y:"T"})}}n{$("#F").34(f+="&1y="+(1p 33().32()),9(){16();$("#K").C();1u("#F a.18");$("#8").r({Y:"T"})})}}3(!m[\'1A\']){o.21=9(e){3(e==M){I=2w.2v}n{I=e.2u}3(I==27){G()}}}}31(e){}}9 1m(){$("#K").C();$("#8").r({Y:"T"})}9 G(){$("#2Y").N("s");$("#Z").N("s");$("#8").2X("2W",9(){$(\'#8,#B,#1F\').2V("24").N().C()});$("#K").C();3(2t o.v.J.2i=="2g"){$("v","11").r({A:"1Z",z:"1Z"});$("11").r("22","")}o.1h="";o.21="";H P}9 16(){$("#8").r({2U:\'-\'+20((13/2),10)+\'p\',z:13+\'p\'});3(!(1V.1q.2Q&&1V.1q.2P<7)){$("#8").r({38:\'-\'+20((1a/2),10)+\'p\'})}}9 2p(a){6 b={};3(!a){H b}6 c=a.1B(/[;&]/);25(6 i=0;i<c.1c;i++){6 d=c[i].1B(\'=\');3(!d||d.1c!=2){39}6 e=2a(d[0]);6 f=2a(d[1]);f=f.2r(/\\+/g,\' \');b[e]=f}H b}9 2x(){6 a=o.2M;6 w=1S.2o||1R.2o||(a&&a.1Q)||o.v.1Q;6 h=1S.1P||1R.1P||(a&&a.2n)||o.v.2n;1O=[w,h];H 1O}9 1K(){6 a=2K.2J.1C();3(a.O(\'2I\')!=-1&&a.O(\'3o\')!=-1){H 1b}}',62,211,'|||if|div|id|var||TB_window|function||||||||||||||else|document|px|append|css|click||href|body||||width|height|TB_overlay|remove|TB_Counter|TB_TempArray|TB_ajaxContent|tb_remove|return|keycode|style|TB_load|src|null|unbind|indexOf|false|title|TB_NextHTML|imgPreloader|block|iframe|ajaxContentH|ajaxContentW|this|display|TB_closeWindowButton||html|goPrev|TB_WIDTH|TB_PrevHTML|TB_iframeContent|tb_position||thickbox|tb_show|TB_HEIGHT|true|length|nbsp|span|Math|onload|onkeydown|goNext|Esc|or|close|tb_showIframe|TB_imageCount|Close|new|browser|TB_FoundURL|Key|Image|tb_init|name|imgLoader|TB_NextURL|random|TB_NextCaption|modal|split|toLowerCase|TB_PrevCaption|urlNoQuery|TB_HideSelect|TB_PrevURL|TB_ajaxWindowTitle|img|addClass|tb_detectMacXFF|TB_ImageOff|150|rel|arrayPageSize|innerHeight|clientWidth|self|window|children|TB_prev|jQuery|frameborder|TB_next|getElementById|auto|parseInt|onkeyup|overflow|alt|unload|for|inlineId||100||unescape|1000|round|hspace|TB_closeAjaxWindow|TB_title|undefined|match|maxHeight|TB_iframe|bmp|gif|png|clientHeight|innerWidth|tb_parseQuery|jpeg|replace|jpg|typeof|which|keyCode|event|tb_getPageSize|show|TB_overlayBG|TB_closeWindow|TB_overlayMacFFBGHack|TB_secondLine|TB_caption|blur|TB_Image|60|tb_pathToImage|mac|userAgent|navigator|of|documentElement|Prev|lt|version|msie|gt|ready|Next|marginLeft|trigger|fast|fadeOut|TB_imageOff|hidden||catch|getTime|Date|load|safari|get|TB_inline|marginTop|continue|scrollTop|TB_modal|class|TB_|45|440|40|630|input|188|190|substr|try|area|firefox'.split('|'),0,{}));
