﻿function initHomepage () {
	//$(window).bind("load", function(){

			initTopTen();
			addLanguageMenu ("jp");
			equalizeVerticalDividers();
			initMenu();
			bindFix();
			sidebar();
			installRegistration();
			install_newsletter_Registration();
//	});
}



function initTopTen() {
	window.toptenUI_title = $('#top10Title').clone();
	window.toptenUI_content = $('#top10').clone();
	$('#top10Title').remove();
	$('#top10').remove();
	
	//topTen();
	//startFlash();
	checkForVideo();
}


function topTen(){
	window.top10running = 1;
	$('#flashColumn').empty().append($(window.toptenUI_title).clone())
		.append($(window.toptenUI_content).clone());
		$('#top10Title, #top10').css({"visibility":"visible", "opacity":0}).animate({
			"opacity":1}, 400, function(){
				$('.top10LeftArrow, .top10RightArrow').unbind("mousedown");
				$('.top10LeftArrow').css("cursor","pointer").mousedown(function(){
					if ($(this).hasClass('top10ArrowActive')) {
						$('.top10Sprite').animate({"left":"+=580px"},200);
					}
					if ($(this).hasClass('top10done')) {
						top10done();
					}
				}).hover(
					function(){
						if ($(this).hasClass('top10ArrowActive')) {
							$(this).addClass('top10ArrowHover');
						}
					},
					function(){
						$(this).removeClass('top10ArrowHover');
					});
					
				$('.top10RightArrow').css("cursor","pointer").mousedown(function(){
					if ($(this).hasClass('top10ArrowActive')) {
						$('.top10Sprite').animate({"left":"-=580px"},200);
					}
					if ($(this).hasClass('top10done')) {
						top10done();
					}
				}).hover(
					function(){
						if ($(this).hasClass('top10ArrowActive')) {
							$(this).addClass('top10ArrowHover');
						}
			
					},
					function(){
						$(this).removeClass('top10ArrowHover');
				});
			
			});
	

}



function top10done() {
	$('body').append('<div id="buffer"><div class="fadein"></div></div>');
	$('.fadein').css("opacity","0");
	$('#flashColumn').prepend($('.fadein'));
	$('.fadein').animate({"opacity":"1"},300,function(){
		window.top10running = 0;
		$('#buffer').remove();
		startFlash();
	});
}



function flashdone(){
	topTen();
}


function startFlash(){
	$('#flashColumn').empty().attr("href","media/synfora_flash09_v2_sm.swf").media({
			params: {wmode: 'transparent', bgColor: '#000000', zIndex:'1'},
			attrs: {wmode: 'transparent', bgColor: '#000000', zIndex:'1'},
						wmode: 'transparent',
			width: 580,
			height: 250,
			bgColor: "#07153F"
			});
}


function top10_clicked() {
	topTen();
}



function fixTop10() {
	if(window.navHover == 1) {
	if ($('#top10').length) {
		$('#top10, #top10Title').fadeOut(250,function(){
			$('#top10, #top10Title').css("z-index","-1");
		});
	}
	}
	
}

function restoreTop10() {
	if(window.navHover == 0) {
		$('#top10, #top10Title').css("z-index","1");
		$('#top10, #top10Title').fadeIn(300, function(){
			if ($('#top10').css("opacity") != "1" || $('#top10Title').css("opacity") != "1" ) {
				setTimeout("restoreTop10()",150);
			}
		});	
	} else {
		setTimeout("restoreTop10()",500);
	}
}





function bindFix(){
	$('.sf-menu').hover(
		function(){
			window.navHover = 1;
			fixTop10();
		},
		function(){
			window.navHover = 0;
			setTimeout("restoreTop10()",500);
		}
 	)
}


function sidebar(){

	$('#topTenButton').click(function(){
		topTen();
	});
	
	$('#videoApp').css("cursor","pointer").click(function(){
		location.href= ("applications/video.html");
		}).hover(function(){
			swapImg09 ($(this), "images/videoApplications_h.gif");
		},function(){
			swapImg09 ($(this), "images/videoApplications.gif");
	});
	
	
	$('#imagingApp').css("cursor","pointer").click(function(){
		location.href= ("applications/imaging.html");	
		}).hover(function(){
			swapImg09 ($(this), "images/imagingApplications_h.gif");
		},function(){
			swapImg09 ($(this), "images/imagingApplications.gif");
	});
	
	$('#wirelessApp').css("cursor","pointer").click(function(){
		location.href= ("applications/wireless.html");		
		}).hover(function(){
			swapImg09 ($(this), "images/wirelessApplications_h.gif");
		},function(){
			swapImg09 ($(this), "images/wirelessApplications.gif");
	});
	
	$('#picoforSOC').css("cursor","pointer").click(function(){
		location.href= ("products/soc.html");		
		}).hover(function(){
			swapImg09 ($(this), "images/picoforSOC_h.gif");
		},function(){
			swapImg09 ($(this), "images/picoforSOC.gif");
	});
	
	$('#picoforFPGA').css("cursor","pointer").click(function(){
		location.href= ("products/fpga.html");		
		}).hover(function(){
			swapImg09 ($(this), "images/picoforFPGA_h.gif");
		},function(){
			swapImg09 ($(this), "images/picoforFPGA.gif");
	});
}	
	
function swapImg09(target, img) {
	$(target).css({"backgroundImage":'url('+img+')'});
}

function equalizeVerticalDividers() {
	var equalizeHeightList =["#featured", "#ofInterest"];
	var maxheight = 0;
	$.each(equalizeHeightList, function(i, val){
			var thisheight = $(val).innerHeight(false);
			if (thisheight > maxheight) {
				maxheight = thisheight;
			}
			if (i == equalizeHeightList.length - 1) {
				$("#featured, #ofInterest").css("height",maxheight);
			}
	
	});
}