/*

- Schooler Kellogg, Co.
- http://www.schoolerkellogg.com
- designed by Switch Creative Group
- http://www.groupswitch.com

*/

/* ! ---- Site Functions ---- */
/* ---------------------------------------------------- */
	
	$(document).ready(function(){
		
		
		/* ! Header | superfish */
		/* ---------------------------------------- */
			$('#nav_list').superfish();
			
		
		/* ! Footer | bottom alignment */
		/* ---------------------------------------- */ 
			
			// set the footer size
			function setFooter() {
			
				var windowHeight = 0;
				windowHeight = $(window).height();
				var wrapperHeight = $('#wrapper').outerHeight();

				if (windowHeight - wrapperHeight >= 0) {
					$("#wrapper").css('height', (windowHeight + "px"));
					$('#ftr_hldr').css('position', 'absolute');
				} else {
					$("#wrapper").css('height', 'auto');
					$('#ftr_hldr').css('position', 'relative');
				}
					
			}
			
			// place footer
			setFooter();
			
			$(window).resize(function(){
				setFooter();
			});
		
		
		/* ! Home Page | flash embed */
		/* ---------------------------------------- */
			var video_array 	= new Array ('video_01', 'video_06', 'video_04');
			var random_number = Math.floor(Math.random()*video_array.length);

			$('#home_video').append('<img src="_videos/videos/' + video_array[random_number] + '.jpg" alt="home" width="1024" height="576" />');
			
			var flashvars = {};
			var params = { wmode: "transparent" };
			var attributes = {};
			var callback = function (){};
			swfobject.embedSWF("_videos/" + video_array[random_number] + ".swf", "home_video", 1024, 576, "10", "_videos/Scripts/expressinstall.swf", flashvars, params);
		
		
		/* ! Gallery Pages | gallery functions */
		/* ---------------------------------------- */
			if ($('#gal_scroll').length >= 1) {
			
				var left_width = 1024 - 65 - $('#gal_list li:eq(1)').width();
				$('#mc_left').css('width', left_width+'px');
				
				$('#gal_scroll').addClass('working').removeClass('scroll');
				
				var gal = $('#gal_list li');
				
				var gal_spacing 	= new Array();		// array for creating total width
				var gal_move 			= new Array();		// array for item positions
				var view_width 		= 1024;						// width of viewable area
				var spacer_width 	= 5;							// border between items
				var total_width 	= 0;							// total width of items
				var current 			= 0;							// current item
				var items					= gal.length-1		// 1 less due to the #mc_left
				
				for (i=0; i<gal.length; i++) {
					gal_spacing[i] = $(gal[i]).outerWidth();									// find the width of each item
					total_width = total_width + gal_spacing[i];								// add that to the total width
					gal_move[i] = -total_width + view_width + spacer_width;		// * each move - the total width (with each iteration) + the view width + the spacer
				}
				gal_move.shift(); 																					// remove the first item because it's copy
				
				$('#gal_list').width(total_width);
				
				var gal_nav = '<div id="gal_nav">';
				gal_nav += '<div id="gn_left">';
				gal_nav += '<p>' + (current+1) + '/' + items + '</p>';
				gal_nav += '</div>';
				gal_nav += '<div id="gn_right">';
				gal_nav += '<p><a href="#" id="prev">&laquo; Prev</a> / <a href="#" id="next">Next &raquo;</a></p>';
				gal_nav += '</div>';
				gal_nav += '<div class="clear"></div>';
				gal_nav += '</div>';
				$('#main_content').prepend(gal_nav);
	
	
				$('#next').click(function(){
					current++;
					if (current >= items) {
						current = 0;
					}
					$('#gal_list').animate({ 'left': (gal_move[current]) + 'px' }, 'slow');
					$('#gn_left p').text((current+1) + '/' + items);
				});
				
				
				$('#prev').click(function(){
					current--;
					if (current < 0) {
						current = items-1;
					}
					$('#gal_list').animate({ 'left': gal_move[current] + 'px' }, 'slow');
					$('#gn_left p').text((current+1) + '/' + items);
				});
			
			}

	
	});
	
	
	
	
	
