$(document).ready(function(){
	$("a.glow").hover(function() { //When trigger is clicked...
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).attr('id', 'glow');

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("a#glow").removeAttr('id')
		});

		//Following events are applied to the trigger (Hover events for the trigger)
	});
	
	// panel slide
	$(".tab,.tab2").click(function(){
		$("#areas").slideToggle("slow");
		$(this).toggleClass("active"); return false;
	});

	// specials coupons
	$(".coupons h2:first").addClass("active");
	$(".coupons ul").show();

	$(".coupons h2").click(function(){
		$(this).next("ul").slideToggle("slow")
		.siblings("ul:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h2").removeClass("active");
	});
	
	// randomize on refresh (will block items below)
	randomizeIt();

	// list items clickable
	$(".service-grouping li").click(function(){
		window.location=$(this).find("a").attr("href"); return false;
	});
	
	// fancybox
	$("a.zoom").fancybox();

	// fancyvideo
	$("a[@rel*=fancyvideo]").fancybox({
		overlayShow: true,
		frameWidth:480,
		frameHeight:385
	});
});

// randomize on refresh
function randOrd(){ return (Math.round(Math.random())-0.5); } 	
function randomizeIt() { 
	var nShow = 8; 
	var tarr = new Array(nShow); 
	for (var i=0; i<tarr.length; i++) { tarr[i] = i; } 
	tarr.sort( randOrd );
	//alert(tarr.join('\n')); // for testing
	for(var i=0; i<1; i++) { 
		var divlocn = 'rdiv'+tarr[i];   
		document.getElementById(divlocn).style.display = 'block'; 
	}
}

/*
//Index Image Rotation
function theRotator() {
	//Set the opacity of all images to 0
	$('div#slides ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	$('div#slides ul li:first').css({opacity: 1.0});
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('rotate()',6000);
}
function rotate() {	
	//Get the first image
	var current = ($('div#slides ul li.show')?  $('div#slides ul li.show') : $('div#slides ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div#slides ul li:first') :current.next()) : $('div#slides ul li:first'));	
	
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};
$(document).ready(function() {		
	//Load the slideshow
	theRotator();
});*/

$(window).load(function(){
	// nivo slider
	$(".slider.services").nivoSlider({
		effect: "fade", // random, fold, fade, sliceDown(Left), sliceUp(Left,Down,DownLeft)
		slices: 15,
		animSpeed: 750, // slide transition speed
		pauseTime: 5000,
		startSlide: 0, // set starting slide (0 index)
		directionNav: false, // next & prev
		directionNavHide: true, // only show on hover
		controlNav: true, // 1,2,3...
		controlNavThumbs: false, // use thumbnails for control nav
		controlNavThumbsFromRel: false, // use image rel for thumbs
		controlNavThumbsSearch: ".jpg", // replace this with...
		controlNavThumbsReplace: "_sm.jpg", // ...this in thumb img src
		keyboardNav: true, // use left & right arrows
		pauseOnHover: true, // stop animation while hovering
		manualAdvance: false, // force manual transitions
		captionOpacity: 0.8, // universal caption opacity
		beforeChange: function(){},
		afterChange: function(){},
		slideshowEnd: function(){} // triggers after all slides have been shown
	});
});

// dropdowns
$(function(){
	$("ul.dropdown li").hover(function(){
		$(this).addClass("hover");
		$('ul:first',this).css('visibility', 'visible');
	},function(){
		$(this).removeClass("hover");
		$('ul:first',this).css('visibility', 'hidden');
	});
	$("ul.dropdown li ul li:has(ul)").find("a:first").append(" &raquo; ");
});
