function getSCookie(c_name) {
  var search = c_name + "=";
  var returnvalue = "";
  if (document.cookie.length > 0) {
    var offset = document.cookie.indexOf(search);
    if (offset != -1) { 
      offset += search.length;
      var end = document.cookie.indexOf(";", offset);
      if (end == -1) {end = document.cookie.length;}
      returnvalue=unescape(document.cookie.substring(offset, end));
      }
   }
  return returnvalue;
}

function detectActive() {
	var ActiveLeft;
	var ActiveRight;
	if(document.getElementById('apps').style.display.match('block')) {ActiveLeft='2';}
	else if(document.getElementById('tools').style.display.match('block')) {ActiveLeft='3';}
	else {ActiveLeft='1';}
	if(document.getElementById('buy').style.display.match('block')) {ActiveRight='5';}
	else if(document.getElementById('partner').style.display.match('block')) {ActiveRight='6';}
	else {ActiveRight='4';}
	return ActiveLeft+ActiveRight;
}

function setSCookie() {
	//document.cookie="ltabs="+detectActive();
}

function checkSCookie() {
	var tab_selected=window.document.location.hash.replace("#","");
	if(window.document.location.hash!=="") {
		if(tab_selected=="productTab") {product_selected();}
		else if(tab_selected=="appsTab") {apps_selected();}
		else if(tab_selected=="toolsTab") {tools_selected();}
		else if(tab_selected=="supportTab") {support_selected();}
		else if(tab_selected=="buyTab") {buy_selected();}
		else if(tab_selected=="partnerTab") {partner_selected();}
		else {}
	}
	var lasttabs=getSCookie('ltabs');
	if(lasttabs!==null && lasttabs!=="") {
		if(tab_selected!="productTab" && tab_selected!="appsTab" && tab_selected!="toolsTab") {
			if(lasttabs.match("1")) {product_selected();}
			else if(lasttabs.match("2")) {apps_selected();}
			else {tools_selected();}
		}
		if(tab_selected!="supportTab" && tab_selected!="buyTab" && tab_selected!="partnerTab") {
			if(lasttabs.match("4")) {support_selected();}
			else if(lasttabs.match("5")) {buy_selected();}
			else {partner_selected();}
		}
	}
}

function winHeight() {
	var myHeight=0;
	if(typeof(window.innerWidth)=='number') { //Non-IE
		myHeight=window.innerHeight;
	} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { //IE 6+ in 'standards compliant mode'
		myHeight=document.documentElement.clientHeight;
	} else if(document.body && (document.body.clientWidth || document.body.clientHeight)) { //IE 4 compatible
		myHeight=document.body.clientHeight;
	}
	return myHeight;
}

function findPos(obj) {
	var curtop=0;
	if(obj.offsetParent) {
		do {curtop+=obj.offsetTop;}
		while(obj=obj.offsetParent);
	return curtop;
	}
}

/*
var sfUL=document.getElementById("hp_content").getElementsByTagName("UL");
for (var j=1;j<sfUL.length;j++) {
	var checkEl=sfUL[j];
	if(sfUL[j].offsetHeight=="0"){
		var tabID="";
		while(tabID=="" || tabID==undefined) {
			checkEl=checkEl.parentNode;
			tabID=checkEl.getAttribute('id');
		}
		if(tabID!="buy") {
			checkEl.style.position="absolute";
			checkEl.style.display="block";
		}
	}
	if((findPos(sfUL[j])+sfUL[j].offsetHeight)>(winHeight()-38) && (sfUL[j].offsetHeight<sfUL[0].offsetHeight || sfUL[j].offsetHeight>(sfUL[0].offsetHeight+10))){
		sfup=sfUL[j].offsetHeight+2;
		sfUL[j].style.marginTop='-'+sfup+'px';
	}
	checkEl.style.position="";
	checkEl.style.display="";
}*/

var sfHover;
sfHover = function() {
	var sfEls = document.getElementById("hp_content").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

var promoFunc= new Array;
promoFunc.four_changePromo_1=function(){
 $('.main_promo').hide();
 $('.main_promo').attr('src', 'theme/renesas_interactive/pix/mainPromo_2.jpg');
 $("#promo1_off").hide();
 $("#promo1_on").show();
 if(sidFlg>0) {$('.main_promo').animate({opacity: "show"}, 500);}
 else {$('.main_promo').animate({opacity: "show"}, 1000);}
 $('.main_promo').attr('alt', 'SAVE 50% on Tools');
// $('.main_promo_url').attr('href', '/fmwk.jsp?cnt=/ddd_landing.jsp&fp=/support/ddd&site=i&campaign=rotate_ddd');
 //$('.four_on1').attr('href', '/fmwk.jsp?cnt=/ddd_landing.jsp&fp=/support/ddd&site=i&campaign=rotate_ddd');
 
  $('.main_promo_url').attr('href', $('.four_on1').attr('href'));

 $("#promo2_on").hide();
 $("#promo2_off").show();
 $("#promo3_on").hide();
 $("#promo3_off").show();
 $("#promo4_on").hide();
 $("#promo4_off").show();
}
promoFunc.four_changePromo_2=function(){
 $('.main_promo').hide();
 $('.main_promo').attr('src', 'theme/renesas_interactive/pix/mainPromo.jpg');
 $("#promo2_off").hide();
 $("#promo2_on").show();
 if(sidFlg>0) {$('.main_promo').animate({opacity: "show"}, 500);}
 else {$('.main_promo').animate({opacity: "show"}, 1000);}

 $('.main_promo').attr('alt', 'FREE Sample Code');
 //$('.main_promo_url').attr('href', '/fmwk.jsp?cnt=software_landing.jsp&fp=/support/software/&campaign=rotate_gsce');
 //$('.four_on2').attr('href', '/fmwk.jsp?cnt=software_landing.jsp&fp=/support/software/&campaign=rotate_gsce');

  $('.main_promo_url').attr('href', $('.four_on2').attr('href'));

 $("#promo1_on").hide();
 $("#promo1_off").show();
 $("#promo3_on").hide();
 $("#promo3_off").show();
 $("#promo4_on").hide();
 $("#promo4_off").show();
}
promoFunc.four_changePromo_3=function(){
 $('.main_promo').hide();
 $('.main_promo').attr('src', 'theme/renesas_interactive/pix/mainPromo_3.jpg');
 $("#promo3_off").hide();
 $("#promo3_on").show();
 if(sidFlg>0) {$('.main_promo').animate({opacity: "show"}, 500);}
 else {$('.main_promo').animate({opacity: "show"}, 1000);}

 $('.main_promo').attr('alt', 'Ultra Fast Flash MCU');
 //$('.main_promo_url').attr('href', '/fmwk.jsp?cnt=sh_child_sh7216.htm&fp=/products/mpumcu/reach_further/child_folder/&title=SH7216&campaign=rotate_sh7216');
 //$('.four_on3').attr('href', '/fmwk.jsp?cnt=sh_child_sh7216.htm&fp=/products/mpumcu/reach_further/child_folder/&title=SH7216&campaign=rotate_sh7216');

  $('.main_promo_url').attr('href', $('.four_on3').attr('href'));

 $("#promo1_on").hide();
 $("#promo1_off").show();
 $("#promo2_on").hide();
 $("#promo2_off").show();
 $("#promo4_on").hide();
 $("#promo4_off").show();
}
promoFunc.four_changePromo_4=function(){
 $('.main_promo').hide();
 $('.main_promo').attr('src', 'theme/renesas_interactive/pix/mainPromo_4.jpg');
 $("#promo4_off").hide();
 $("#promo4_on").show();
 if(sidFlg>0) {$('.main_promo').animate({opacity: "show"}, 500);}
 else {$('.main_promo').animate({opacity: "show"}, 1000);}

 $('.main_promo').attr('alt', 'Power MOSFET Simulation Site');
 //$('.main_promo_url').attr('href', '/fmwk.jsp?cnt=vp_landing.jsp&fp=/products/discrete/power_mos/vp/&title=Renesas%20VP&campaign=rotate_vp');
 //$('.four_on4').attr('href', '/fmwk.jsp?cnt=vp_landing.jsp&fp=/products/discrete/power_mos/vp/&title=Renesas%20VP&campaign=rotate_vp');

  $('.main_promo_url').attr('href', $('.four_on4').attr('href'));

 $("#promo1_on").hide();
 $("#promo1_off").show();
 $("#promo2_on").hide();
 $("#promo2_off").show();
 $("#promo3_on").hide();
 $("#promo3_off").show();
}
var sidFlg=0;
$(document).ready(function(){
	$("#search").hover(changeBG,backToNormal);
	
	/*  ==============================================================
	 *  hover functions for 4 promo homepage
	 *  ==============================================================
	 */
$(".four_hover1").hover(function(){sidFlg=1;promoFunc['four_changePromo_1']();},function(){return});
$(".four_hover2").hover(function(){sidFlg=1;promoFunc['four_changePromo_2']();},function(){return});
$(".four_hover3").hover(function(){sidFlg=1;promoFunc['four_changePromo_3']();},function(){return});
$(".four_hover4").hover(function(){sidFlg=1;promoFunc['four_changePromo_4']();},function(){return});

var sld=2;
function promSildeShow() {
  if(sidFlg>0) {return;}
  promoFunc['four_changePromo_'+sld]();
  if(sld==4) {sld=1} else {sld++}
  setTimeout(promSildeShow, 5000);
}
setTimeout(promSildeShow, 5000);

	/*  ==============================================================
	 *  Tab behaviours
	 *  ==============================================================
	 */	
	$("a.product_tab").click(product_selected);
	$("a.apps_tab").click(apps_selected);
	$("a.tools_tab").click(tools_selected);
	$("a.buy_tab").click(buy_selected);
	$("a.support_tab").click(support_selected);
	$("a.partner_tab").click(partner_selected);
	
	/*  ==============================================================
	 *  Homepage bottom search behaviours
	 *  ==============================================================
	 	
	$("#doc_search").hover(search_docs, function() {  }); 
	$("#app_notes").hover(search_apps, function() {  });
	$("#faq").hover(search_faqs, function() {  });
	$("#parametric_search").hover(search_para, function() {  });
	*/

	/*  ==============================================================
	 *  Menu flyouts
	 *  ==============================================================
	 */	
	$(".americas_flyout").hover(showRegions, hideRegions);
$(".europe_flyout").hover(showRegions2, hideRegions2);
$(".asia_flyout").hover(showRegions3, hideRegions3);
	
	/*  ==============================================================
	 *  other behaviours 
	 *  ==============================================================
	 */	
	
	$("a.top").click(function() {$("#double_panel").slideToggle()});
		
	$("#double_panel").hover(function() { /*do nothing */ }, function() {
		$("#double_panel").animate({opacity: "hide"}, 1500);
	});
}); // close document.ready

function changeBG(){  
	var browserName=navigator.appName;
	if (browserName=="Microsoft Internet Explorer")  {
		$("#search").css({ background:"url('theme/renesas_interactive/pix/para_bg_ie.gif') 0px 0px no-repeat", top:"-7px", right: "-10px", height:"55px", width:"330px" }); 
	}  else   {
		$("#search").css({ background:"url('theme/renesas_interactive/pix/para_bg.png') 0px 0px no-repeat", top:"-7px", right: "-10px", height:"55px", width:"330px" }); 
	}
	
	$(".searcher").css({ top:"8px" });
	$("a.search_btn img").css({ top:"7px", right:"10px" });
	$("input.search").css({ top:"8px" });
	$("#para_search").show();
}

function backToNormal(){ 
	$("#search").css({ background:"url('theme/renesas_interactive/pix/search_bg.png') 0px 1px no-repeat", top:"0px", right: "0px", height:"19px", width:"320px" });	
	$(".searcher").css({ top:"1px" });
	$("a.search_btn img"). css({ top:"0px", right:"0px" });
	$("input.search").css({ top:"1px" });
	$("#para_search").hide();
}


function exposeAbout(){  
	$("#about_hover").show();
	$(".about_renesas").css({ background:"url('theme/renesas_interactive/pix/about_hover_bg.png') 8px 1px no-repeat", color:"#cd0003" });
}

function hideAbout(){  
	$("#about_hover").hide();
	$(".about_renesas").css({ background:"url('theme/renesas_interactive/pix/headerArrowOff.gif') 95px 5px no-repeat", color:"#666" });
}


function product_selected() {
	//switch tab graphics
	$('.tab_product').attr('src', 'theme/renesas_interactive/pix/tab_product_selected.png');
	$('.tab_apps').attr('src', 'theme/renesas_interactive/pix/tab_apps_normal.png');
	$('.tab_tools').attr('src', 'theme/renesas_interactive/pix/tab_tools_normal.png');
	
	//turn on/off visibility to divs
	$("#products").show();
	$("#apps").hide();
	$("#tools").hide();
}

function apps_selected() {
	//switch tab graphics
	$('.tab_apps').attr('src', 'theme/renesas_interactive/pix/tab_apps_selected.png');
	$('.tab_tools').attr('src', 'theme/renesas_interactive/pix/tab_tools_normal.png');
	$('.tab_product').attr('src', 'theme/renesas_interactive/pix/tab_product_normal.png');
	
	//turn on/off visibility to divs
	$("#apps").show();
	$("#tools").hide();
	$("#products").hide();

}

function tools_selected() {
	//switch tab graphics
	$('.tab_apps').attr('src', 'theme/renesas_interactive/pix/tab_apps_normal.png');
	$('.tab_tools').attr('src', 'theme/renesas_interactive/pix/tab_tools_selected.png');
	$('.tab_product').attr('src', 'theme/renesas_interactive/pix/tab_product_normal.png');
	
	//turn on/off visibility to divs
	$("#tools").show();
	$("#products").hide();
	$("#apps").hide();
}

function buy_selected() {
	//switch tab graphics
	$('.tab_buy').attr('src', 'theme/renesas_interactive/pix/tab_buy_selected.png');
	$('.tab_support').attr('src', 'theme/renesas_interactive/pix/tab_support_normal.png');
	$('.tab_partner').attr('src', 'theme/renesas_interactive/pix/tab_partner_normal.png');
	
	//turn on/off visibility to divs
	$("#buy").show();
	$("#support").hide();
	$("#partner").hide();
}

function support_selected() {
	//switch tab graphics
	$('.tab_support').attr('src', 'theme/renesas_interactive/pix/tab_support_selected.png');
	$('.tab_partner').attr('src', 'theme/renesas_interactive/pix/tab_partner_normal.png');
	$('.tab_buy').attr('src', 'theme/renesas_interactive/pix/tab_buy_normal.png');
	
	//turn on/off visibility to divs
	$("#support").show();
	$("#partner").hide();	
	$("#buy").hide();
}

function partner_selected() {
	//switch tab graphics
	$('.tab_partner').attr('src', 'theme/renesas_interactive/pix/tab_partner_selected.png');
	$('.tab_support').attr('src', 'theme/renesas_interactive/pix/tab_support_normal.png');
	$('.tab_buy').attr('src', 'theme/renesas_interactive/pix/tab_buy_normal.png');
	
	//turn on/off visibility to divs
	$("#partner").show();
	$("#support").hide();
	$("#buy").hide();
}


function search_docs() {
	
	//turn on/off visibility to input divs and buttons
	$(".docs").show();
	$(".apps").hide();
	$(".faqs").hide();
	$(".para").hide();
	
	//change all other backgrounds to white
	$("#app_notes").css({ background:"#fff", color:"#7096a2" });
	$("#faq").css({ background:"#fff", color:"#7096a2" });
	$("#parametric_search").css({ background:"#fff", color:"#7096a2" });
	
	//change app_notes bg and color
	$("#doc_search").css({ background:"#f0f0f0", color:"#000" });	
}

function search_apps() {
	
	//turn on/off visibility to input divs and buttons
	$(".apps").show();
	$(".docs").hide();
	$(".faqs").hide();
	$(".para").hide();
	
	//change all other backgrounds to white
	$("#doc_search").css({ background:"#fff", color:"#7096a2" });
	$("#faq").css({ background:"#fff", color:"#7096a2" });
	$("#parametric_search").css({ background:"#fff", color:"#7096a2" });
	
	//change app_notes bg and color
	$("#app_notes").css({ background:"#f0f0f0", color:"#000" });	
}

function search_faqs() {
	
	//turn on/off visibility to input divs and buttons
	$(".faqs").show();
	$(".docs").hide();
	$(".apps").hide();
	$(".para").hide();
	
	//change all other backgrounds to white
	$("#doc_search").css({ background:"#fff", color:"#7096a2" });
	$("#app_notes").css({ background:"#fff", color:"#7096a2" });
	$("#parametric_search").css({ background:"#fff", color:"#7096a2" });
	
	//change app_notes bg and color
	$("#faq").css({ background:"#f0f0f0", color:"#000" });	
}

function search_para() {
	
	//turn on/off visibility to input divs and buttons
	$(".para").show();
	$(".docs").hide();
	$(".apps").hide();
	$(".faqs").hide();
	
	//change all other backgrounds to white
	$("#doc_search").css({ background:"#fff", color:"#7096a2" });
	$("#app_notes").css({ background:"#fff", color:"#7096a2" });
	$("#faq").css({ background:"#fff", color:"#7096a2" });
	
	//change app_notes bg and color
	$("#parametric_search").css({ background:"#f0f0f0", color:"#000" });	
}

function showRegions () {
	$("#region_flyout").show();
	$("a.am").css({ color:"#666" });
}

function hideRegions() { 
	$("#region_flyout").hide();
	$(".americas_flyout a").css({ color:"#7096a2" });
}

function showRegions2() {
	$("#region_flyout2").show();
	$("a.eu").css({ color:"#666" });
}

function hideRegions2() { 
	$("#region_flyout2").hide();
	$(".europe_flyout a").css({ color:"#7096a2" });
}

function showRegions3() {
	$("#region_flyout3").show();
	$("a.as").css({ color:"#666" });
}

function hideRegions3() { 
	$("#region_flyout3").hide();
	$(".asia_flyout a").css({ color:"#7096a2" });
}

/*  ==============================================================
 *  Control of return page
 *  ==============================================================
 */
	if(window.document.location.hash!=="") {
	  var tab_selected=window.document.location.hash.replace("#","");
	  if(tab_selected=="productTab") {product_selected();}
	  else if (tab_selected=="appsTab") {apps_selected();}
	  else if(tab_selected=="toolsTab") {tools_selected();}
	  else if(tab_selected=="supportTab") {support_selected();}
	  else if(tab_selected=="buyTab") {buy_selected();}
	  else if(tab_selected=="partnerTab") {partner_selected();}
	  else {}
	}