/************************************

1) Header Random Picture Function
2) Open/Closed Sign
3) Picture Page slideshow
4) Nav Menu Hover Effect

************************************/

/************************************
1) Header Random Picture Function
************************************/
function randomPic()
{
	var picture = "picture_inframe01.jpg";
	number = Math.floor(Math.random()*4)
	switch(number){
		case 0:
			var picture = "picture_inframe01.jpg";
		break;
		case 1:
			var picture = "picture_inframe02.jpg";
		break;
		case 2:
			var picture = "picture_inframe03.jpg";
		break;
		case 3:
			var picture = "picture_inframe04.jpg";
		break;
		default:
			var picture = "picture_inframe04.jpg";
	}
	return picture;
}

/************************************
2) Open/Closed Sign
************************************/
function openclosed() {
	//variables
	today = new Date();
	weekday = today.getDay();
	hour = today.getHours();
	open = 0;
	
	//set open to true on certain days and times
	if(weekday >= 2 && weekday <= 6) {
		if(hour >= 11 && hour < 14 || hour >= 17 && hour < 21)
		open = 1;
	}
	if(weekday == 0) {
		if(hour >= 11 && hour < 14)
		open = 1;
	}
	//output open or not
	if(open == 0)
		document.write("<img src='../images/closed_sign.gif' alt='sign' width='128' height='117' />");
	if(open == 1)
		document.write("<img src='../images/open_sign.gif' alt='sign' width='128' height='117' />");
}


$(document).ready(function() {
	//display the random picture at the top of the page
	var pic = randomPic();
	$("img#random-pic").attr('src', 'images/' + pic);
	
	//motion tweaking on menu pages
	$("a.anchorLink").click(function(event){
		event.preventDefault()
		var full_url = this.href; //get the full url - like mysitecom/index.htm#home
		var parts = full_url.split("#"); //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
		var trgt = parts[1];
		var target_offset = $("#"+trgt).offset();	//get the top offset of the target anchor
		var target_top = target_offset.top;
		$('html, body').stop().animate({scrollTop:target_top}, 1000, 'easeInOutCubic');	//goto that anchor by setting the body scroll top to anchor top
	});
	
/************************************
3) Picture Page slideshow
************************************/
	$('div#slideshow').cycle({
		timeout:         4500,    // milliseconds between slide transitions (0 to disable auto advance)
		speed:           750,     // speed of the transition (any valid fx speed value) 
		fx: 			'uncover' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	});
	
/************************************
4) Nav Menu Hover Effect
************************************/
	//disable CSS hover effect on nav
	$('ul.css-override').removeClass("css-override");
	
	//create nav button animation function
	navAnimate = function(buttonString, xVal, yVal){
		shiftVal = -47;
		newyVal = yVal + shiftVal;
		$(buttonString).hover(
			function() {
				$(this).stop().animate(
					{'background-position': xVal + 'px ' + newyVal + 'px'},
					800,
					'easeOutElastic')
			},
			function() {
				$(this).stop().animate(
					{'background-position': xVal + 'px ' + yVal + 'px'},
					800,
					'easeOutElastic')
			}
		);
	}
	
	//animate each nav button
	navAnimate('#nav-bar a.btn-home',0,0);
	navAnimate('#nav-bar a.btn-menu',-112,0);
	navAnimate('#nav-bar a.btn-groups',-224,0);
	navAnimate('#nav-bar a.btn-history',-336,0);
	navAnimate('#nav-bar a.btn-pictures',-448,0);
	navAnimate('#nav-bar a.btn-about',-560,0);

});

/* IE PNG fix multiple filters
(function ($) {
	if (!$) return;
	$.fn.extend({
		fixPNG: function(sizingMethod, forceBG) {
				if (!($.browser.msie)) return this;
				var emptyimg = "empty.gif"; //Path to empty 1x1px GIF goes here
				sizingMethod = sizingMethod || "scale"; //sizingMethod, defaults to scale (matches image dimensions)
				this.each(function() {
						var isImg = (forceBG) ? false : jQuery.nodeName(this, "img"),
								imgname = (isImg) ? this.src : this.currentStyle.backgroundImage,
								src = (isImg) ? imgname : imgname.substring(5,imgname.length-2);
						this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + sizingMethod + "')";
						if (isImg) this.src = emptyimg;
						else this.style.backgroundImage = "url(" + emptyimg + ")";
				});
				return this;
		}
	});
})(jQuery);
*/
