/* ---------------------------------------------------------------------
Original Author: Kelly Meath
------------------------------------------------------------------------ */
/*
var userAgent = navigator.userAgent.toLowerCase();
jQuery.browser = {
	version: (userAgent.match( /.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/ ) || [])[1],
		chrome: /chrome/.test( userAgent ),
		safari: /webkit/.test( userAgent ) && !/chrome/.test( userAgent ),
		opera: /opera/.test( userAgent ),
		msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
		mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};
*/
jQuery( function($) {
	
	$('.top_cat').click( function(){
		$('.top_cat').removeClass('active');
		$(this).addClass('active');
	});
	/*
	if (jQuery.browser.safari || jQuery.browser.chrome) { 
		$('#page_title').css('right' , '66px');
	}
	*/
	$('#header').sortable({ containment: 'parent' , items: '.square' });
	
	$('.square').hover( function(){
		if($(this).hasClass('sound1')){ soundManager.play('sound1'); }
		if($(this).hasClass('sound2')){ soundManager.play('sound2'); }
		if($(this).hasClass('sound3')){ soundManager.play('sound3'); }
		if($(this).hasClass('sound4')){ soundManager.play('sound4'); }
		if($(this).hasClass('sound5')){ soundManager.play('sound5'); }
	}, function(){
		$(this).removeClass('white green gray tan top bottom right left center').addClass(randomSQ());
		$('span',this).css('opacity' , '0').animate({ opacity : 1}, 2000);		
	});

	$('.square').mousedown(
		function(){ 
			$(this).addClass('moving');
		}
	).mouseup(
		function(){ 
			$(this).removeClass('moving');
		}
	);
	
	$('.square').click( function(){
		$('span', this).removeClass('white green gray tan top bottom right left center').addClass(randomSQ());
	});
	
	$('.hrefRemove').removeAttr('href');
	
	$('embed').attr('wmode', 'opaque');
	
	$('object').prepend('<param name="wmode" value="opaque" />').attr('wmode', 'opaque');
	
	$('.hidden').hide().removeClass('hidden');
	
	$('.show').click( function() {
		var removeActive = "." + $(this).parent().parent().attr('class') + " li a";
		$(removeActive + ', .sublist li a').removeClass('active');
		var showItem = "."+$(this).attr('id');
		if($(this).hasClass('home')){
			var activePage = "#"+$(this).attr('id');
			$(activePage).addClass('active');
		} else {
			$(this).addClass('active');
		}
		$('.visible').hide(500, function(){
			$(this).removeClass('visible');
			$(showItem).show(500).addClass('visible');
		});
	});
	
	$('.showImage').click( function() {
		var removeActive = "." + $(this).parent().parent().attr('class') + " li a";
		$(removeActive).removeClass('active');
		var showItem = "."+$(this).attr('id');
		var imgGroup = "visibleImage"+showItem.split('-')[1];
		$(this).addClass('active');
		$("."+imgGroup).hide(500, function(){
			$(this).removeClass(imgGroup);
		});
		$(showItem).addClass(imgGroup).show(500, function(){
			$('html, body').animate({ scrollTop: $("#middle_container").offset().top}, 250);
		});		
	});	
	
	var totalSChomeImages = $('.content_images > .showcase_home').size();
	var counter = 1;
	$(".content_images").everyTime(5000,function(i) {
		if ( $('.schome').is(':visible') ) { 													  
			if(counter == totalSChomeImages){
				$('.content_images .showcase_home:eq('+(totalSChomeImages-1)+')').hide(1000);
				$('.content_images .showcase_home:eq(0)').show(1000, function(){
					$('html, body').animate({ scrollTop: $("#middle_container").offset().top}, 250);																					
					counter=1;	
				});	
			} else {
				$('.content_images .showcase_home:eq('+(counter-1)+')').hide(1000);
				$('.content_images .showcase_home:eq('+counter+')').show(1000, function(){
					$('html, body').animate({ scrollTop: $("#middle_container").offset().top}, 250);																					
					counter++;	
				});	
			}
		}
	});				 
	
	$('.close').removeAttr('style').css('opacity' , '0').removeClass('hidden');
	$('.employee_photo').toggle( function(){
		$(this).addClass('drop_shadow').animate({height: '527px', width: '527px'}, 1000, function(){
			$(this).addClass('scroll');	
			$('.close', this).animate({opacity: 1}, 1000);
		});
	}, function(){
		$(this).removeClass('drop_shadow scroll').animate({height: '32px', width: '32px'}, 500);
		$('.close', this).animate({opacity: 0}, 500);
		$(this).scrollTop(0);
	});

});

function randomSQ(){
	var colorSQ=Math.floor(Math.random()*4);
	var positionSQ=Math.floor(Math.random()*5);
	switch(colorSQ){
		case 0:
			var color = 'white ';
			break;
		case 1:
			var color = 'green ';
			break;
		case 2:
			var color = 'gray ';
			break;	
		case 3:
			var color = 'tan ';
			break;				
	}
	if(color != 'tan '){
		switch(positionSQ){
			case 0:
				var position = 'top';
				break;
			case 1:
				var position = 'right';
				break;
			case 2:
				var position = 'bottom';
				break;
			case 3:
				var position = 'left';
				break;
			case 4:
				var position = 'center';
				break;				
		}
	} else {
		var position = 'center';
	}
	return color+position;
}

function getScrollBarWidth () {
	var inner = document.createElement('p');
	inner.style.width = "100%";
	inner.style.height = "200px";
	var outer = document.createElement('div');
	outer.style.position = "absolute";
	outer.style.top = "0px";
	outer.style.left = "0px";
	outer.style.visibility = "hidden";
	outer.style.width = "200px";
	outer.style.height = "150px";
	outer.style.overflow = "hidden";
	outer.appendChild (inner);
	document.body.appendChild (outer);
	var w1 = inner.offsetWidth;
	outer.style.overflow = 'scroll';
	var w2 = inner.offsetWidth;
	if (w1 == w2) w2 = outer.clientWidth;
	document.body.removeChild (outer);
	return (w1 - w2);
};