// Once document is loaded$(document).ready(function(){	// -----------------------------------------------------------	// Hide RHS tabs not selected	// -----------------------------------------------------------		// Identify selected tab	var selected_tab = "#" + $(".rhs-box-tabbed h2.selected a").attr("rel") + "-" + $(".rhs-box-tabbed h2.selected a").attr("title");		// Hide all other tabs        $(".rhs-box-tabbed " + selected_tab).show();	//$(".rhs-box-tabbed .tab-inner:not(" + selected_tab + ")").hide();			// -----------------------------------------------------------	// Change RHS tabs when clicked	// -----------------------------------------------------------        // Remove HREF - only needed if JS wont work        $(".rhs-box-tabbed h2 a").attr("href",'javascript:void(0);');	$(".rhs-box-tabbed h2 a").click(function () {				// Identify which tab box we are dealing with		var tab_box = $(this).attr("rel");		var new_tab = $(this).attr("title");				// Hide all tab contents		$("#" + tab_box + " .tab-inner").hide();		// Disable all tabs		$("#" + tab_box + " h2").removeClass('selected');		// Enable the selected tabs		$("#" + tab_box + " h2:has(a[title='"+new_tab+"'])").addClass('selected');		// Fade in the new tab contents		$("#"+tab_box+"-"+new_tab).fadeIn("slow");	  	});		// -----------------------------------------------------------	// Magazine frontpage toggle for blurb	// -----------------------------------------------------------        // Javascript is supported        $(".mag-box-lefttab-tabarea h3 a").attr("href",'javascript:void(0);');        $(".mag-box-highlight-imageselect a").attr("href",'javascript:void(0);');        $(".mag-box-highlight-options .blurbtoggle").attr("href",'javascript:void(0);');	// Fade toggle function	jQuery.fn.fadeToggle = function(speed, easing, callback) {	   return this.animate({opacity: 'toggle'}, speed, easing, callback);	}; 		$(".mag-box-highlight-options .blurbtoggle").click(function () {		$(".mag-box-highlight-blurb").fadeToggle("slow");	});		// -----------------------------------------------------------	// Change highlights box article left-hand side tab	// -----------------------------------------------------------		$(".mag-box-lefttab-tabarea h3 a").click(function () {				// Identify which tab box we are dealing with		var selected_highlight = $(this).attr("rel");				// Hide all tab contents		$(".mag-box-lefttab-content .mag-box-right:visible").hide();				// Show the new tab contents		$("#" + selected_highlight).removeClass("mag-box-highlight-noshow");		$("#" + selected_highlight).fadeIn("slow");		// Disable all tabs		$(".mag-box-lefttab-tabarea .mag-box-lefttab-tab").addClass('headline');		$(".mag-box-lefttab-tabarea .mag-box-lefttab-tab .number-square").addClass('number-circle number-offset');		$(".mag-box-lefttab-tabarea .mag-box-lefttab-tab .number-square").removeClass('number-square');		$(".mag-box-lefttab-tabarea .mag-box-lefttab-tab").removeClass('mag-box-lefttab-tab');				// Enable the selected tab		$(".mag-box-lefttab-tabarea .headline:has(a[rel='" + selected_highlight + "']) .number-circle").addClass('number-square');		$(".mag-box-lefttab-tabarea .headline:has(a[rel='" + selected_highlight + "']) .number-circle").removeClass('number-offset number-circle');		$(".mag-box-lefttab-tabarea .headline:has(a[rel='" + selected_highlight + "'])").addClass('mag-box-lefttab-tab');		$(".mag-box-lefttab-tabarea .headline:has(a[rel='" + selected_highlight + "'])").removeClass('headline');	  	});		// ---------------------------------------------------------------------	// Some highlights have multiple images attached to them	// ---------------------------------------------------------------------		$(".mag-box-highlight-imageselect a").click(function () {				// Identify which image and tab box we are dealing with		var new_image = $(this).attr("rel");		var image_selector = $(this).find("span").attr("id");		var highlight_name = image_selector.substr(0,10);				if ( highlight_name.substr(0,8) == "mag-high" )		{			// Change image and the selected number			$("#"+highlight_name+" .mag-box-highlight-image").css("background-image", "url("+new_image+")");			$("#"+highlight_name+" .mag-box-highlight-imageselect span").removeClass("number-circle");			$("#"+highlight_name+" .mag-box-highlight-imageselect #"+image_selector).addClass("number-circle");						// Hide the blurb if we're not looking at the first image			if ( image_selector.substr(15,16) != "1" ) {				$(".mag-box-highlight-blurb").fadeOut("medium");			} else {				$(".mag-box-highlight-blurb").fadeIn("medium");			}		} else {			// Invalid highlight box, exit			return;		}	  	});	// ---------------------------------------------------------------------	// Fancy captions for images that are overlayed	// ---------------------------------------------------------------------        // We have javascript, so disable the fallback captions        $('.article-container .wp-caption p').hide();        $('.article-body .wp-caption img[title]').captify({                // all of these options are... optional                // ---                // speed of the mouseover effect                speedOver: 'fast',                // speed of the mouseout effect                speedOut: 'normal',                // how long to delay the hiding of the caption after mouseout (ms)                hideDelay: 500,                // 'fade', 'slide', 'always-on'                animation: 'always-on',                // text/html to be placed at the beginning of every caption                prefix: '',                // opacity of the caption on mouse over                opacity: '0.7',                // the name of the CSS class to apply to the caption box                className: 'caption-bottom',                // position of the caption (top or bottom)                position: 'bottom',                // caption span % of the image                spanWidth: '100%'        });	// -----------------------------------------------------------	// Comments forms need to clear themselves when clicked	// -----------------------------------------------------------        $('#comment-form .comment-content input:not(#submit)').focus( function() {            if ( this.value == this.defaultValue && (this.defaultValue == 'Name' || this.defaultValue == 'E-mail address                  (this will not be published)') ) this.value='';        });        $('#comment-form .comment-content input#submit').click( function(e) {            var strName    = $('#comment-form .comment-content input:not(#submit)').val();            var strComment = $('#comment-form .comment-content textarea').val();            if ( strName == 'Name' || strComment == 'Your comments on this article...' || !strName || !strComment )            {                // Haven't filled in a name                if ( $('#wpcf_msg').length > 0 )                {                    $('<div></div>').append('To send us a message, you need to fill in your name, e-mail address and your message.').dialog();                } else {                    $('<div></div>').append('To add a comment on this article you need to enter at least a comment and your name.').dialog();                }                return false;            } else {                $('#comment-form .comment-content form').submit();            }        });        $('#comment-form .comment-content textarea').focus( function() {            if ( this.value == this.defaultValue ) this.value='';        });	// -----------------------------------------------------------	// Allow the typing of a page number...	// -----------------------------------------------------------        $('.page-number').focus( function() {            var strVal = $(this).val();            if ( strVal.indexOf('/') != -1 )            {                strVal = strVal.substr( 0, strVal.indexOf('/') );                $(this).val( strVal );                $(this).select();            }        });        $('.page-number').keyup( function(e) {            if ( e.keyCode == 13 )            {                var strVal = $(this).val();                if ( strVal == parseInt( strVal ) )                {                    var strURI = window.location.href;                    if ( strURI.indexOf( '#' ) != -1 ) strURI = strURI.substr( 0, strURI.indexOf( '#' ) );                    if ( strURI.indexOf( '?' ) != -1 ) strURI = strURI.substr( 0, strURI.indexOf( '?' ) );                    var newURI;                    if ( strURI.indexOf( 'page-' ) != -1 )                    {                        newURI = strURI.substr( 0, strURI.indexOf( 'page-' ) + 5 ) + strVal;                        window.location.replace( newURI );                    } else {                        if ( strURI.substr(strURI.length - 1,1) == '/' )                        {                            newURI = strURI + 'page-' + strVal;                        } else {                            newURI = strURI + '/page-' + strVal;                        }                        window.location.replace( newURI );                    }                }            }        });	// -----------------------------------------------------------	// JavaScript required warnings need to be hidden - since we have it	// -----------------------------------------------------------        $('.java-error-box').hide();        // Show things that need JavaScript        $('#comment-form .comment-content input#submit').show();	// -----------------------------------------------------------	// Social bookmarking	// -----------------------------------------------------------        $('.rhs-box-simple li:contains(Share)').click( function() {           $('#social-bookmark').dialog('open');        });        try {            $('#social-bookmark').bookmark({                popup: false,                compact: false            });            bookmark_loaded = true;        } catch(err_name) {            bookmark_loaded = false;        }	// -----------------------------------------------------------	// Popup windows, if there are any...	// -----------------------------------------------------------        try {            $.ui.dialog.defaults.bgiframe = true;            $.ui.dialog.defaults.autoOpen = true;            $.ui.dialog.defaults.modal = true;            $.ui.dialog.defaults.buttons = {                "Continue": function() {                    $(this).dialog("close");                }            };            $.ui.dialog.defaults.title = 'Note';            $('#simple-popup').dialog();            $('#social-bookmark').dialog({                title: 'Share this page',                width: 600,                buttons: {                "Cancel": function() {                    $(this).dialog("close");                }},                autoOpen: false,                resizable: false            });            dialog_loaded = true;        } catch(err_name) {            dialog_loaded = false;        }	// ---------------------------------------------------------------------	// Search form	// ---------------------------------------------------------------------	objSearchInput = $('#search-input');        objSearchInput.focus(function() { if ( $(this).val() == 'Search articles...' ) $(this).val(''); })            .blur(function() { if ( $(this).val() == '' ) $(this).val('Search articles...'); })            .keyup(function(e) {                if ( e.keyCode == 13 )                {                    // Submit the form                    window.location.replace( '/magazine/search/' + escape($(this).val()) );                }            });	// ---------------------------------------------------------------------	// Route image splash swap	// ---------------------------------------------------------------------	$('#route-splash-switch div').click(function() {            // Add new active            var objThis = $(this);            // Change route image            $('#route-splash').css( 'background', 'url(/images/route/splash'+objThis.attr('class')+'.jpg) no-repeat' );        });	// ---------------------------------------------------------------------	// Route screenshots	// ---------------------------------------------------------------------        $('#route-screenshots a').click(function(e) {            window.open( $(this).attr('href') );            e.preventDefault();            return false;        });        $('#route-screenshot-link').show().css('visibility','visible').click( function() {            $('#route-screenshots').dialog({                title: 'Screenshots of grough route in action',                width: 690,                height: 400,                buttons: {                "Close": function() {                    $(this).dialog("close");                }},                autoOpen: false,                resizable: false            }).dialog('open');        });});
