/* ===========================================================================
 * Filename: javascript/functions.js
 * Author: Webmistress, info@webmistress.com.au, www.webmistress.com.au
 * Copyright: Webmistress except where noted
 * Date: 17 Aug 2009
 * Description: Contains JavaScript functions for the Rockwall Bar and Grill website.
 *
 * This file may not be used for any purpose other than for the Rockwall Bar and Grill
 * website and may not be modified without written permission from the author.
 * =========================================================================== 
 */

/* Google map functions */
/*
$(window).resize(function()
{
	if(typeof loadMap==='function')
		loadMap();
});

$(window).unload(function()
{
	if(typeof GUnload==='function')
		GUnload();
});

$(document).ready(function()
{
	if(typeof loadMap==='function')
		loadMap();
});
 */

$(window).resize(function()
{
	if(typeof initialise_gmap==='function')
		initialise_gmap();
});

$(document).ready(function()
{
	if(typeof initialise_gmap==='function')
		initialise_gmap();
});

$(document).ready(function()
{	
	// External links
	$("a[rel='external']").attr("target","_blank");
	
	// Paragraphs containing images
	$("p > img.image-left").parent().css("padding-bottom","0");
	$("p > img.image-right").parent().css("padding-bottom","0");
	
	// Design enhancements
	//$("#page").append("<div id=\"mask\"></div>");
	$("#content").prepend("<div id=\"heading\"></div>");
	
	// Fix PNG for IE6
	$(document).pngFix();
	
	// Add caption to feature links
	$("#featurelinks a").each(
		function( intIndex )
		{
			var caption = $(this).find("img").eq(0).attr("alt");
			$(this).append("<span>" + caption + "</span>");
		}
	);
	
	// Design enhancement - extended bar for feature links box
	if ( $("#featurelinks").length > 0 )
	{
		$("#page").wrap("<div id=\"wrapper-inner\"></div>");
		var offset = $("#featurelinks").offset();
		$("#wrapper-inner").css("background", "transparent url(/new/theme/images/featurebar.gif) no-repeat scroll 50% " + (offset.top-50) + "px");
	}
		
	// Menu toggles
	$("a.menu-toggle").show();
	$("a.menu-toggle").parent().next("ul").wrap("<div class=\"menu-reveal\"></div>");
	$("div.menu-reveal").hide();
	
	$("a.menu-toggle").each(
		function( intIndex )
		{
			var closeLink = $("<p><a href=\"#\" class=\"menu-close\">Close</a></p>");
			$(this).parent().next(".menu-reveal").append(closeLink);
			
			$(closeLink).click(function () 
				{
					$(this).closest("div.menu-reveal").slideUp();
					
					var showHideLink = $("a.menu-toggle").eq(intIndex);
					var showHideLinkText = $(showHideLink).text();
					var showHideNewText = showHideLinkText.replace(/Hide/, "View");
					$(showHideLink).text(showHideNewText);
					
					return false;
				});
			}
	);
	
	$("a.menu-toggle").click(function () 
	{
		var linktext = $(this).text();
		if ($(this).parent().next("div.menu-reveal").eq(0).is(":hidden")) 
		{
			var newtext = linktext.replace(/View/, "Hide");
			$(this).text(newtext);
			$(this).parent().next("div.menu-reveal").eq(0).slideDown();
			return false;
		} 
		else 
		{
			var newtext = linktext.replace(/Hide/, "View");
			$(this).text(newtext);
			$(this).parent().next("div.menu-reveal").eq(0).slideUp();
			return false;
		}
	});
	
});

/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch() {
    var $active = $('#slideshow img.active');

    if ( $active.length == 0 ) $active = $('#slideshow img:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow img:first');

    // uncomment the 3 lines below to pull the images in random order
    
     var $sibs  = $active.siblings();
     var rndNum = Math.floor(Math.random() * $sibs.length );
     var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 5000 );
});
