function getStyle(x,styleProp)	{
	if (x.currentStyle)
		var y =X.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function hide(obj) {
    obj.style.visibility = "hidden"
}

function show(obj) {
    obj.style.visibility = "visible"
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function submenuOn(objID,sub_objID,additionalTop)	{
	additionalTop = additionalTop || 0;
	var Aobj = objID.parentNode.getElementsByTagName("div");
	for(var i=0; i<Aobj.length;i++) {
		if(Aobj[i].className == 'submenu') {
			Aobj[i].style.display = 'none';
		}
	}
	var position = findPos(objID);
	var newLeft = position[0];
	if(additionalTop == 0)	{
		var newTop = position[1]+objID.offsetHeight+13;
		// remove one px for IE
		if(document.all)	{
			newTop = newTop-1;
		}
	}
	else	{
		var newTop = position[1]+objID.offsetHeight+additionalTop;
	}
	
	document.getElementById(sub_objID).style.left = newLeft+'px';
	document.getElementById(sub_objID).style.top = newTop+'px';
	document.getElementById(sub_objID).style.display = 'block';
}

function submenuOff(objID,sub_objID)	{
	timer = setTimeout("closeSubMenu('" + sub_objID + "');",300);
}

function closeSubMenu(sub_objID)	{
	if ( typeof ( timer ) != "undefined" )	{
		clearTimeout(timer);
	}
	document.getElementById(sub_objID).style.display = 'none';
}

function persistSubMenu() {
	clearTimeout(timer);
}

function removeFirstSeparator(objID)	{
	if(document.getElementById(objID))	{
		var Aobj = document.getElementById(objID).getElementsByTagName("li");
		if(Aobj.length == 0)	{
			var Aobj = document.getElementById(objID).getElementsByTagName("a");
		}
		Aobj[0].style.border = 0;
		Aobj[0].style.marginLeft = "0px";
		Aobj[0].style.paddingLeft = "0px";
		if(objID === 'mainlevelmainLinks')	{
			Aobj[0].style.marginLeft = "-8px";
			Aobj[0].style.paddingLeft = "8px";
		}
	}
}

function setCookie (cookieName, cookieValue, expires, path, domain, secure) {
	document.cookie = escape(cookieName) + '=' + escape(cookieValue) 
	+ (expires ? '; EXPIRES=' + expires : '')
	+ (path ? '; PATH=' + path : '')
	+ (domain ? '; DOMAIN=' + domain : '')
	+ (secure ? '; SECURE' : '');
}

function getCookie (cookieName) {
  var cookieValue = null;
  var posName = document.cookie.indexOf(escape(cookieName) + '=');
  if (posName != -1) {
    var posValue = posName + (escape(cookieName) + '=').length;
    var endPos = document.cookie.indexOf(';', posValue);
    if (endPos != -1)
      cookieValue = unescape(document.cookie.substring(posValue, endPos));
    else
      cookieValue = unescape(document.cookie.substring(posValue));
  }
  return cookieValue;
}

function getParam(paramName){
	//returns the value of the requested querystring parameter
	var docLoc = document.location.href;
	var qString = '';
	var params = new Array();

	if(docLoc.indexOf("?") != -1){
		qString = document.location.href.split("?");
		qString = qString[1];
	}

	if(qString.indexOf("&") != -1){
		params = qString.split("&");
	}
	else if(qString.indexOf("=") != -1){
		params[params.length] = qString;	
	}

	for(i=0; i<params.length; i++){
		param = params[i].split("=");
		if(param[0] == paramName){
			return param[1];	
		}
	}
	return '';
}

function setLastCountryCookie(js_location,quicklink) {
	//( 2678400 = 31 days )
	var now = new Date();
	now.setTime(now.getTime()+ 1000 * 60 * 60 * 24 * 365);
	setDateCookie ('PrefOption', quicklink, now);
	if(gpp) {
		setCookie ('location', js_location, now);
	} else {
		setCookie ('contact', js_location, now);
	}
}

function setDateCookie (cookieName, cookieValue, expires, path, domain, secure) {
  document.cookie = escape(cookieName) + '=' + escape(cookieValue) 
    + (expires ? '; EXPIRES=' + expires.toGMTString() : '')
    + (path ? '; PATH=' + path : '')
    + (domain ? '; DOMAIN=' + domain : '')
    + (secure ? '; SECURE' : '');
}

function setOpacity(obj, value){
	if(obj != null) {
		if(document.all){
			obj.style.filter = 'alpha(opacity=' + value + ')';
		}
		else {
			obj.style.opacity = (value/100); 
		}	
	}
}

function toggleDiv(objId){
	//close open divs
	var div = document.getElementById(objId);
		
	if(document.getElementById('bio_div') && div.id != 'bio_div'){
		document.getElementById('bio_div').style.visibility = 'hidden';
	}
	if(document.getElementById('blog_div') && div.id != 'blog_div'){
		document.getElementById('blog_div').style.visibility = 'hidden';
	}
	if(document.getElementById('highlights_div') && div.id != 'highlights_div'){
		document.getElementById('highlights_div').style.visibility = 'hidden';
	}

	if(div.style.visibility == 'hidden'){
		div.style.visibility = 'visible';
		div.style.position = 'absolute';
		div.style.backgroundColor = "#FFFFFF";
		setOpacity(div, 75);
	}
	else {
		div.style.visibility = 'hidden';
	}	
	
}

/**
* Functions for the image transforms
**/

/**
* Global variables for the functions
**/
imgobj = '';
fadeincount=0;
fadeoutcount=100;
fadeinimg='';
fadeoutimg='';

/**
* ImageCarousel object
**/
var imageCarousel = new ImageCarousel();
function ImageCarousel(){
	this.currPos = 0;
	this.fadePos = 1;
	this.imageArr = new Array();
	
	this.getNextImage = function(){
		if(this.currPos == this.imageArr.length) {
			return null;
		} else {
			returnVal = this.imageArr[this.currPos%this.imageArr.length];	
		}
		this.currPos++;
		return returnVal;
	}	

	this.getFadeImageIds = function(){
		returnVal = new Object();
		returnVal.nextimg = parseInt(this.fadePos) + 1;
		returnVal.currimg = parseInt(this.fadePos);
 		if(this.fadePos == this.imageArr.length) {
 			this.fadePos = 1;
 			returnVal.nextimg = 1;
 		} else {
 			this.fadePos++;
 		}
		return returnVal;
	}
	
	this.addImage = function(imageUrl) {
		this.imageArr[this.imageArr.length] = imageUrl;	
	}	
}


/**
* Function to fade in a new image
**/
function transition() {
	imgobj = imageCarousel.getFadeImageIds();
	fadeinimg=imgobj.nextimg;
	fadeoutimg=imgobj.currimg;
	if(fadeinimg != fadeoutimg) {
		fadeInGraphic();
	}
}

/**
* Fade in a new image and fade out the current image
**/
function fadeInGraphic() {
	//alert("setOpacity - img"+fadeinimg);
	if(fadeinimg==1)	{
		setOpacity(document.getElementById("img"+fadeoutimg),fadeoutcount);
	}
	else	{
		setOpacity(document.getElementById("img"+fadeinimg),fadeincount);
	}
	fadeincount += 12;
	fadeoutcount -= 12;
	if (fadeincount<100) {
		setTimeout("fadeInGraphic();",50);
	} else {
		setOpacity(document.getElementById("img"+fadeinimg),100);
		setOpacity(document.getElementById("img"+fadeoutimg),0);		
		fadeincount = 0;
		fadeoutcount = 100;
		setTimeout("transition();",5000);	
	}
}

//RIBBON FUNCTIONS START
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

function moveSlideshow(elementID,final_x,final_y,interval) {
    if (!document.getElementById) return false;
    
    // if the element does not exist we have nothing to do
    if (!document.getElementById(elementID)) return false;
    var elem = document.getElementById(elementID);
    
    // the slideshow events stack up and the animation is not smooth anymore
    if (elem.movement) {
        clearTimeout(elem.movement);
    }
    
    // current slideshow position
    var xpos = parseInt(elem.style.left);
    var ypos = parseInt(elem.style.top);
    if (xpos == final_x && ypos == final_y) {
        return true;
    }
    
    // restrict moving to white area
    if (final_x <= -elem.max_x) {
        final_x = -elem.max_x;
    }
    if (final_x > 0) {
	    final_x = 0;
    }
    
    // animation code
    if (xpos < final_x) {
        var dist = Math.ceil((final_x - xpos)/10);
        xpos = xpos + dist;
    }
    if (xpos > final_x) {
        var dist = Math.ceil((xpos - final_x)/10);
        xpos = xpos - dist;
    }
  
    // again, restrict showing white area
    if (xpos <= -elem.max_x) {
	    xpos = -elem.max_x;
    }
    if (xpos > 0) {
	    xpos = 0;
    }
    
    // fix the elements position
    elem.style.left = xpos + "px";
    elem.style.top = ypos + "px";
    
    // and set up the event again after an interval
    var repeat = "moveSlideshow('"+elementID+"',"+final_x+","+final_y+","+interval+")";
    elem.movement = setTimeout(repeat,interval);
}

function prepareSlideshow() {
	// first lets make sure the browser understands the DOM methods we will be using
  	if (!document.getElementsByTagName) return false;
  	if (!document.getElementById) return false;
  	
	// Make sure the elements exist
  	if (!document.getElementById("slideshow")) return false;
  	var slideshow = document.getElementById("slideshow");
  	var wrapper = document.getElementById("slideshow_wrapper");
  	wrapper.style.overflow = "hidden";
  	
	// prepare the navigation bit we will be using
  	// left
  	var navigation = document.createElement("ul");
  	navigation.setAttribute("id", "navigation");
  	var li = document.createElement("li");
  	var scroll_left = document.createElement("a");
  	scroll_left.setAttribute("id", "scroll_left");
  	scroll_left.href ="#";
  	scroll_left.title = prevImgTxt;
  	var text = document.createTextNode("Left");
  	scroll_left.appendChild(text);
  	li.appendChild(scroll_left);
  	navigation.appendChild(li);
  	
  	if(previousLink!="#")	{
	  	var li = document.createElement("li");
	  	var previous_left = document.createElement("a");
	  	previous_left.setAttribute("id", "previous_left");
	  	previous_left.href = previousLink;
	  	previous_left.title = prevCollectionTxt;
	  	var text = document.createTextNode("Previous");
	  	previous_left.appendChild(text);
	  	li.appendChild(previous_left);
	  	navigation.appendChild(li);
	}
  	
  	slideshow.insertBefore(navigation, wrapper);
  	
  	//right
  	var li = document.createElement("li");
  	var scroll_right = document.createElement("a");
  	scroll_right.setAttribute("id", "scroll_right");
  	scroll_right.href ="#";
  	scroll_right.title = nextImgTxt;
  	var text = document.createTextNode("Right");
  	scroll_right.appendChild(text);
  	li.appendChild(scroll_right);
  	navigation.appendChild(li);
  	
  	if(nextLink!="#")	{
	  	var li = document.createElement("li");
	  	var next_right = document.createElement("a");
	  	next_right.setAttribute("id", "next_right");
	  	next_right.href = nextLink;
	  	next_right.title = nextCollectionTxt;
	  	var text = document.createTextNode("Next");
	  	next_right.appendChild(text);
	  	li.appendChild(next_right);
	  	navigation.appendChild(li);
	}
  	
  	slideshow.insertBefore(navigation, wrapper);
	
	var slideshow_set = document.getElementById("slideshow_set");
	slideshow_set.style.top = 0+"px";
	slideshow_set.style.left = 0+"px";
	/*
	for(var i=0; i<arrThumbs.length;i++) {
		var li = document.createElement("li");
		li.id = "thumb"+i;
		var img = document.createElement("img");
		li.appendChild(img);
		img.src = arrThumbs[i].img;
		slideshow_set.appendChild(li);
		var trigger = function(){
			overlayOn(this);
		}
		addEvent(li, 'mouseover', trigger);
		alert(li.id);
	}
	*/
	var imgsWidth = 114;
	var imgsHeight = 51;
	
	// to get the max y position of the gallery image track we need to count all
	// the li items and multiply that number with height
	var li = slideshow_set.getElementsByTagName("li");
	slideshow_set.max_x = (li.length-1) * imgsWidth;
	slideshow_set.max_y = li.length * imgsHeight;
	
	// need the width of the gallery so that they do not scroll vertical
	var width = li.length * imgsWidth;
	slideshow_set.style.width = width + "px";
	
	// Attach onmouseover event for left
  	scroll_left.onclick = function() {
		// get the current position of the gallery element
		if(iSelectedOn-1 >= 0)	{
			selectedOn(iSelectedOn-1,2);
			window.location = arrThumbs[iSelectedOn-1].link;
		}
		/*
		var slideshow_set = document.getElementById("slideshow_set");
		varX= parseInt(slideshow_set.style.left);
		if (x % imgsWidth == 0) {
    		moveSlideshow("slideshow_set",x+imgsWidth*1,0,10);
		}
		*/
		return false;
	}
	
	// Attach onmouseover event for right
  	scroll_right.onclick = function() {
		// get the current position of the gallery element
		if(arrThumbs.length > iSelectedOn+1)	{
			selectedOn(iSelectedOn+1,2);
			window.location = arrThumbs[iSelectedOn+1].link;
		}
		/*
		var slideshow_set = document.getElementById("slideshow_set");
		varX= parseInt(slideshow_set.style.left);
    	if (x % imgsWidth == 0) {
    		moveSlideshow("slideshow_set",x-imgsWidth*1,0,10);
		}
		*/
		return false;
	}
	
	selectedOn(iSelectedOn,1);
	overlayOff();
}
addLoadEvent(prepareSlideshow);

// display an overlay div onmouseover the thumb
function overlayOn(obj,arrIndex)	{
	var overlayDiv = null;
	if(overlayDiv = document.getElementById("overlayDiv"))	{
		document.body.removeChild(overlayDiv);
	}
	var positions = findPos(obj);
	//check if the thumb is completly visibile before applying the onmouseover overlay
	if((obj.offsetLeft+obj.offsetParent.offsetLeft+obj.offsetWidth) < 900)	{
		var overlayDiv = document.createElement("div");
		overlayDiv.setAttribute("id", "overlayDiv");
		var text = document.createTextNode(arrThumbs[arrIndex].txt);
		var span = document.createElement("span");
		span.appendChild(text);
	  	overlayDiv.appendChild(span);
		document.body.appendChild(overlayDiv);
		overlayDiv.style.top = positions[1]-7+"px";
		overlayDiv.style.left = positions[0]+"px";
		overlayDiv.onclick = function() {
			selectedOn(arrIndex);
			window.location = arrThumbs[arrIndex].link;
		}
		overlayDiv.onmouseout = function() {
			if(overlayDiv = document.getElementById("overlayDiv"))	{
				document.body.removeChild(overlayDiv);
			}
		}
	}
	//alert(positions);
}

// remove overlay div 
function overlayOff()	{
	var overlayDiv = null;
	if(overlayDiv = document.getElementById("overlayDiv"))	{
		document.body.removeChild(overlayDiv);
	}
}

// display a red border around the selected thumb
function selectedOn(arrIndex,align)	{
	align = align || 0;
	var selectedDiv = null;
	if(selectedDiv = document.getElementById("thumbSelected"))	{
		selectedDiv.parentNode.removeChild(selectedDiv);
	}
	var selectedThumb = document.getElementById("thumb"+arrIndex);
	//var insideImg = selectedThumb.getElementsByTagName("a");
	var insideImg = selectedThumb.getElementsByTagName("img");
	var selectedDiv = document.createElement("div");
	selectedDiv.setAttribute("id", "thumbSelected");
	selectedThumb.insertBefore(selectedDiv,insideImg[0]);
	
	var imgsWidth = 114;
	var slideshow_set = document.getElementById("slideshow_set");
	//alert(imgsWidth*arrIndex+"---"+document.getElementById("slideshow_wrapper").offsetWidth);
	if(align != 0 && imgsWidth*(arrIndex+1) > document.getElementById("slideshow_wrapper").offsetWidth)	{
		varX= parseInt(slideshow_set.style.left);
		//alert(arrThumbs);
		//alert(arrThumbs.length+"fffff"+arrIndex)
		if(align == 2)	{
			moveSlideshow("slideshow_set",0-imgsWidth*(arrIndex-7),0,34);
		}
		else	{
			slideshow_set.style.left = 0-imgsWidth*(arrIndex-7)+"px";
		}
	}
}

// find an obj positions
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

// populate thumb array
function thumb(img,txt,link)	{
	this.img = img;
	this.txt = txt;
	this.link = link;
}

function addEvent(obj, evtType, trigger){
	if(window.addEventListener){ // Mozilla, Netscape, Firefox
		obj.addEventListener(evtType, trigger, false);
	} else { // IE
		obj.attachEvent('on' + evtType, trigger);
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



function shopinshop() {
window.open('flash/shop/index.html', 'popup', 'width=1024, height=920, location=no, status=no, titlebar=yes, directories=no, menubar=no, toolbar=no, scrollbars=yes,resizable=yes');
}

function newsletter() {
window.open('https://fofa.jp/speedo/a.p/102/', 'popup', 'width=500, height=600, location=no, status=yes, titlebar=yes, directories=no, menubar=no, toolbar=no, scrollbars=yes,resizable=yes');
}

function swym() {
window.open('flash/swym_2009ss1/index.html', 'popup', 'width=1044, height=788, menubar=no, toolbar=no, scrollbars=no');
}

function swym2() {
window.open('flash/swym_2009fw1/index.html', 'popup', 'width=1044, height=788, menubar=no, toolbar=no, scrollbars=no');
}

function link_select(url){
  if(url.options[url.selectedIndex].value){
    location.href = url.options[url.selectedIndex].value;
  }
}