$(document).ready(function(){
	
/* General Functions *************************************************************************************************/

	// Initialize front page fading
		$('#home_billboard_content').innerfade({
						animationtype: 'fade',
						speed: 2000,
						timeout: 5000,
						type: 'sequence',
						containerheight: '270px'
					});
	
	// Text area resize - not implemented
		//$('#contact_textarea').resizable({ autohide: true, minHeight: 100, minWidth: 200 });
	
	// Set management bio corners
		$('.bios').corner();
		// $('.bios img').corner();
	
	//$('#search').value = '';
	
	// $('body').fadeIn('slow');
	
	fadeSwitch = true;
	
	$('#flip_chip_hover').mouseover(
		function() {
			fadeSwitch = false;
			$("#flip_chip_sub").fadeIn("fast");
		});

	$('#flip_chip_hover').mouseout(
		function() {
			fadeSwitch = true;
			$("#flip_chip_sub").fadeOut("fast");
		});

/***************/
	
	$('#package_hover').mouseover(
		function() {
			fadeSwitch = false;
			$("#package_sub").fadeIn("fast");
		});

	$('#package_hover').mouseout(
		function() {
			fadeSwitch = true;
			$("#package_sub").fadeOut("fast");
		});

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

	$('#fine_pitch_hover').mouseover(
		function() {
			fadeSwitch = false;
			$("#fine_pitch_sub").fadeIn("fast");
		});

	$('#fine_pitch_hover').mouseout(
		function() {
			fadeSwitch = true;
			$("#fine_pitch_sub").fadeOut("fast");
		});
	
/***************/

	$('#BGA_hover').mouseover(
		function() {
			fadeSwitch = false;
			$("#BGA_sub").fadeIn("fast");
		});

	$('#BGA_hover').mouseout(
		function() {
			fadeSwitch = true;
			$("#BGA_sub").fadeOut("fast");
		});

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

	$('#ball_bonding_hover').mouseover(
		function() {
			fadeSwitch = false;
			$("#ball_bonding_sub").fadeIn("fast");
		});

	$('#ball_bonding_hover').mouseout(
		function() {
			fadeSwitch = true;
			$("#ball_bonding_sub").fadeOut("fast");
		});


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

	$('#stud_bumping_hover').mouseover(
		function() {
			fadeSwitch = false;
			$("#stud_bumping_sub").fadeIn("fast");
		});

	$('#stud_bumping_hover').mouseout(
		function() {
			fadeSwitch = true;
			$("#stud_bumping_sub").fadeOut("fast");
		});

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

	$('#wafer_dicing_hover').mouseover(
		function() {
			fadeSwitch = false;
			$("#wafer_dicing_sub").fadeIn("fast");
		});

	$('#wafer_dicing_hover').mouseout(
		function() {
			fadeSwitch = true;
			$("#wafer_dicing_sub").fadeOut("fast");
		});



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

	$('#3d_packaging_hover').mouseover(
		function() {
			fadeSwitch = false;
			$("#3d_packaging_sub").fadeIn("fast");
		});

	$('#3d_packaging_hover').mouseout(
		function() {
			fadeSwitch = true;
			$("#3d_packaging_sub").fadeOut("fast");
		});

	
/* Specific Browser Hacks *************************************************************************************************/
	
		if ($.browser.msie) {
			if ($.browser.version == '7.0') { // Check if version 7
				// alert ($.browser.version);
				$(".icon").css("margin", "0 0 0 -20px");
			}
			else { // Version 6 or lower

			}
		}
	
		if ($.browser.mozilla){
		
		}
	
		if ($.browser.safari) {

		}
	

	
/* Menu functions *************************************************************************************************/

	// Primary Menu
	// Special fix for IE6 mouseover/mouseout events causing flicker, small delay
		$("ul.menu > li").hoverIntent({
						sensitivity: 1, 
						interval: 50, 
						over: expand1, 
						timeout: 125, 
						out: contract1
					});	
	
	// Secondary Menu (Light Gray)
		$("ul.menu > li > ul > li").hover(expand2, contract2);	
		
		// $("ul.menu > li > ul > li").hoverIntent({
		// 						sensitivity: 1, 
		// 						interval: 50, 
		// 						over: expand2, 
		// 						timeout: 125, 
		// 						out: contract2
		// 					});
		
	// Teritary Menu Functions
		$("ul.menu > li > ul > li > ul > li").hover(function(){
			
			// Set light gray menu background to light blue
				$('> a', this).css("background", "#5579b2");
				// alert($('> a', this).text().length);
		
		},function(){
			
			// Restore background color to light gray
			$('> a', this).css("background", "#444");
		
		});


	/* Expand and contract functions ***************************************/

		function expand1() {
		
			// Change top tab background to blue
				$(this).animate( {backgroundColor: '#5579b2'}, 'fast');

			// Change top tab font color to white
				$('> span', this).animate( {color: '#fff'}, 'fast');		

			// Fade in first submenu
				$('> ul', this).fadeIn("fast");
		
			// Set opacity only if not IE - IE 6&7 break
				if (!$.browser.msie) {
					$('> ul', this).animate({ opacity: '.95'}, 10);		
				}
		}
	
		function contract1() {
		
			// Restore white background on top nav tab
				$(this).animate( {backgroundColor: 'white'}, 'fast');				

			// Restore font color on top tab
				$('> span', this).animate( {color: '#5579b2'}, 'fast');

			// Fade out first submenu
				$('> ul', this).fadeOut("fast");

			// Fade out all submenus - Check if needed
		}
	
		function expand2() {
			// $(this).css("margin-bottom", -3);

			// Set 3rd-level menu to postion left of the selected submenu item
				// if ($.browser.msie) {
					// $('> ul', this).css("margin-left", $(this).parent().width() - 16);	// Fix rendering hack for IE
				// }
				// else {
					$('> ul', this).css("margin-left", $(this).parent().width());	
				// }

				// $(this).css("margin", 0);
				// alert($(this).css("margin"));
					
				
				
			// Add blue background color on hover
				$('> a', this).css("background", "#5579b2");

			// Fade in second submenu
				$('> ul', this).fadeIn("fast");
		}

		function contract2() {
			// alert('mouseoff');

			// Reset background to blackish
				$('> a', this).css("background", "#111");
				
			// Fade out second submenu
				$('> ul', this).fadeOut("fast");	
				
				// $(this).css("margin-bottom", 0);
					
		}

 });
