/*

	Elwha River Casino Javascript
	
	This code is (c) Elwha River Casino.  You cannot use this code without expressed permission,
	but otherwise may look it over, play with it and learn from it what you can, as long as you
	don't use *this* exact code in your site.
	
	This code only has two dependencies to work (other than the jQuery Plugins):
		
		jQuery
		Google's Javascript API
		
	Google is included in the <script> tag in the header:
	
		<script src="http://www.google.com/jsapi"></script>
		
	... and jQuery is included just after this line.

*/google.load("jquery","1.4.2");

google.setOnLoadCallback(function(){
								  
/*	
	STEP ONE: Include all external Javascripts.
	-=-=-=-=-=-=-=-=-=-=-=-
	
	We do this so that we can cut down on how many <script> tags are included on the HTML.  The
	goal is to have very unobtrusive HTML so that updates can be made without having to weed
	through piles and piles of code.  This is also why we don't use <table>'s for layouts, just
	tabular data.
	
*/
	
	$.ajaxSetup({async: false});
	$.getScript("inc/curvycorners.js");			// This makes the corners of the content elements round.
	$.ajaxSetup({async: true});
	
	$.ajaxSetup({async: false});
	$.getScript("inc/jquery.innerfade.js");		// This makes the slideshow run (on the front page)
	$.ajaxSetup({async: true});
	
	$.ajaxSetup({async: false});
	$.getScript("inc/jquery.spritely.js");		// This makes the birdy animate.
	$.ajaxSetup({async: true});	
	
	$.ajaxSetup({async: false});
	$.getScript("inc/jquery.simplemodal.js");	// This makes the dark grey, coupon popup.
	$.ajaxSetup({async: true});	
	
	$.ajaxSetup({async: false});
	$.getScript("inc/jquery.random.js");		// This generates random numbers really easily.
	$.ajaxSetup({async: true});	
	
	$.ajaxSetup({async: false});
	$.getScript("inc/jquery.print.js");			// This allows you to print any element on a page.
	$.ajaxSetup({async: true});
	
	$.ajaxSetup({async: false});
	$.getScript("inc/jquery.cookie.js");		// This allows you to read/write cookies very easily.
	$.ajaxSetup({async: true});
	
	$.ajaxSetup({async: false});
	$.getScript("inc/jquery.colorbox.js");		// This allows Colorbox popups (like Lightbox)
	$.ajaxSetup({async: true});
	
	/*
	
		Now that we have plugins out of the way, let's make some settings for the Curvy Corners
		one.  It's the plugin that makes our hard edges round, without the need of extra images,
		CSS or anything else.  It saves us a lot of design time!
	
	*/
	
	var settings = {
      tl: { radius: 30 },
      tr: { radius: 30 },
      bl: { radius: 30 },
      br: { radius: 30 },
      antiAlias: true
    }
	
	/* Use the settings above to apply the Curvy Corners to the layout. */

    curvyCorners(settings, "#content");
	
	if($("body#index").length>0) {					// (i.e. 'If this is the index.html page...)
		curvyCorners(settings, "#rightSideTop");	// ... then apply the round corners to the sidebar
		curvyCorners(settings, "#rightSideBottom");	// elements, as well.
		curvyCorners(settings, "#rightSideBottomest");	// elements, as well.
	}
	
	/*
		Nice, that looks good.  Next step: Make the many <li>'s worth of images fade from one to the other
		within the "Jackpot Winners" box.
	
	*/
	
	$("#eventFader ul").innerfade({
									  
		animationtype: 'fade',	// Fading animation.  (tip: this can also be "slide")
		speed: 'slow',			// Make it slooooow, so that it doesn't give people headaches.
		timeout: 4500,			// Wait 4.5 seconds to switch to the next photo.
		containerheight: '150px'// And never, I mean *never* let the thing be taller than 150px.
	
	});
	
	$("#jackpotWinners ul").innerfade({
									  
		animationtype: 'fade',	// Fading animation.  (tip: this can also be "slide")
		speed: 'slow',			// Make it slooooow, so that it doesn't give people headaches.
		timeout: 5000,			// Wait 4.5 seconds to switch to the next photo.
		containerheight: '150px'// And never, I mean *never* let the thing be taller than 150px.
	
	});
	
	$(".popUps").colorbox({
						  
		opacity: 0.35
	
	});
	
	/*
	
		Next step: the crow.  Now, this says, "crow," but it could be any other animal.
	
		This one uses the jQuery plugin called: Spritely.  It's what lets the crow's wings flap.
		Everything else is done with raw Javascript or jQuery Animate.*/
		
	
	
		crowStartingX = ($("#logo").offset().left+(($("#logo").width())/2));  // Start at the middle of the logo.
		crowStartingY = ($("#logo").offset().top+(($("#logo").height())/2));
	
		$("<div id=\"animal\"></div>").insertAfter("#logo"); // Create the Crow.
	
		$("#animal").css({  //  the crow in it's starting position...
				   
			left: crowStartingX,
			top: crowStartingY
				   
		});
	
		$('#animal').sprite({fps: 4, no_of_frames: 4}).fadeIn().spRandom({
																
			top: 70,
			left: 100,
			right: 200,
			bottom: 340,
			speed: 4000,
			pause: 3000
		  
		});
																
		  // animate 'im...
	
	/* Setup the random coupons.  */
	
		$.ajaxSetup({async: false});
		$.getScript("inc/coupons.js");  // This is the coupons file.  Edit it to manage the coupons.
		$.ajaxSetup({async: true});
	
		$("#animal").click(function(){
	
			if($.cookie('gotCouponToday')!='true') {
							  
				$.modal("<div id=\"couponModal\"><img src=\"images/logo_small.png\" style=\"float:left;margin-right: 10px;\">"+coupon[$.random(coupon.length)]+"<div class=\"columnFix\"></div></div><p id=\"printButton\"><a href=\"javascript:void($('#couponModal').printElement({printMode:'popup'}));\">Print this coupon</a></p>");
			
				$.cookie('gotCouponToday', 'true', { expires: 1 });
	
			} else {
				
				$.modal("<div id=\"couponModal\"><img src=\"images/logo_small.png\" style=\"float:left;margin-right: 10px;\"><h3>Thank You!</h3>Thank you for clicking on the Raven!  You have already received your coupon for today and are not eligible for a new coupon until tomorrow.</div>");
				
			}
							  
		});
	
});