document.write('<style type="text/css">div#content div.overview-cloth ul li a img, div#content div.overview-shoe ul li a img{visibility:hidden;}</style>');

jQuery(document).ready(function(){
	
	initImagePreload();
	initZoom();
	initQuickLinks();
	initSearchBox();
	initFrontBack();
	initSidebarPics();
	initResize();
	initNewsFader();
	initZoomClick();
	initZoomFrontBack();
	initZoomPicture();
	initCustomSelect();
	initHomeFlash();
	initDropDownAthletes();
	
});

	var current = 0;
	var img;
	
function initImagePreload(){
	if (jQuery('div#content div.overview-shoe ul').get(0)){
		isImageLoaded();
	}
	else if (jQuery('div#content div.overview-cloth ul').get(0)){
		isImageLoadedCloth();
	}
}

function isImageLoaded()
{
	var images = jQuery("div#content div.overview-shoe ul li a img");
	var max = jQuery("div#content div.overview-shoe ul li a img").length;
	var src = jQuery(images[current]).attr('src');
	
	img = new Image();
	img.src = src;
	
	if(img.complete){
		jQuery(images[current]).css('display', 'none');
		jQuery(images[current]).css('visibility', 'visible');
		jQuery(images[current]).fadeIn('slow');
		current++;
		if(current<max)
		{
			setTimeout('isImageLoaded()', 0);
		}
	}else{
		if(current<max)
		{
			setTimeout('isImageLoaded()', 0);
		}
	}
}

function isImageLoadedCloth()
{
	var images = jQuery("div#content div.overview-cloth ul li a img");
	var max = jQuery("div#content div.overview-cloth ul li a img").length;
	var src = jQuery(images[current]).attr('src');
	
	img = new Image();
	img.src= src;	
	
	if(img.complete){
		jQuery(images[current]).css('display', 'none');
		jQuery(images[current]).css('visibility', 'visible');
		jQuery(images[current]).fadeIn('slow');
		current++;
		if(current<max)
		{
			setTimeout('isImageLoadedCloth()', 0);
		}
	}else{
		if(current<max)
		{
			setTimeout('isImageLoadedCloth()', 0);
		}
	}
}

function centerPopup()
{
	var winHeight= document.getElementsByTagName('html')[0].clientHeight;
	var popHeight= jQuery('div.news-popup').height();
	jQuery('div.news-popup').css('top', (popHeight>=winHeight)? '0px' : jQuery(document).scrollTop()+(winHeight-popHeight)/2+'px' );
};

function initZoom(){
	jQuery("div#content div.right-detail div.detail-zoom a").css("display", "block");
	return false;
}

function initZoomClick(){
	//Show fader and popup
	jQuery("div#content div.detail-zoom a").click(function(){
		showFader();
		var div = jQuery('div.clothing-popup');
		
		if(div.width > jQuery(window).width()){
			var left = 0;
		}
		else if((jQuery(window).width() - div.width()) < 0){
			var left = 0;
		}
		else{
			var left = (jQuery(window).width() - div.width())/2;
		}
		
		div.css({
			"left": left+'px',
			"visibility": "visible",
			"display": "none"
		});
		div.fadeIn();
		return false;
	});
	//Close fader and popup
	jQuery("div.clothing-popup a.close").click(function(){
		jQuery("#fader").fadeOut();
		jQuery("div.clothing-popup").fadeOut("slow", function(){
			jQuery(this).css({
				"visibility": "hidden",
				"display": "block"
			});
		});
		return false;
	});
}

function initZoomFrontBack(){
	//Change front back pictures in popup
	jQuery("#popup-sm-bk").click(function(){
		//Change big pictures
		jQuery("div.clothing-popup a.front-zoom").addClass("zoom-none");
		jQuery("div.clothing-popup a.back-zoom").removeClass("zoom-none");
		jQuery("div.clothing-popup a.back-zoom").css("display", "none");
		jQuery("div.clothing-popup a.back-zoom").fadeIn();
		//Change small thumbnails
		jQuery(this).hide();
		jQuery("#popup-sm-fr").show();
		return false;
	});
	
	jQuery("#popup-sm-fr").click(function(){
		//Change big pictures
		jQuery("div.clothing-popup a.back-zoom").addClass("zoom-none");
		jQuery("div.clothing-popup a.front-zoom").removeClass("zoom-none");
		jQuery("div.clothing-popup a.front-zoom").css("display", "none");
		jQuery("div.clothing-popup a.front-zoom").fadeIn();
		//Change small thumbnails
		jQuery(this).hide();
		jQuery("#popup-sm-bk").show();	
		return false;	
	});
}

function initZoomPicture(){
	if (jQuery('div.clothing-popup').get(0)){
		var options = {
			zoomType: 'standard',
			zoomWidth: 391,
			zoomHeight: 391,
			position: 'right',
				xOffset: 151,
				yOffset: -24,
				title: 'false'
		};
		jQuery("div.clothing-popup a.front-zoom").jqzoom(options);
		jQuery("div.clothing-popup a.back-zoom").jqzoom(options);
	}
}

function initQuickLinks(){
	// Show Quick links if JavaScript enabled
	jQuery("ul.quick-links li.show a").addClass("active");
	
	jQuery("ul.quick-links li.show a").click(function (){
		jQuery("#quick").slideToggle("slow");
		jQuery("ul.quick-links li.hide a").addClass("active");
		jQuery(this).removeClass("active");
		return false;
	});
	jQuery("ul.quick-links li.hide a").click(function (){
		jQuery("#quick").slideToggle("slow");
		jQuery("ul.quick-links li.show a").addClass("active");
		jQuery(this).removeClass("active");
		return false;
	});
}

function initSearchBox() {
	jQuery("#search").focus(function(){
		if (jQuery(this).val() == 'SEARCH')
			jQuery(this).val('');
	});
	jQuery("#search").blur(function(){
		if (jQuery(this).val() == '')
			jQuery(this).val('SEARCH');
	});
}

function initFrontBack() {

	jQuery("#detail-sm-bk").click(function(){
		//Change big pictures
		jQuery("#detail-big-fr").hide();
		jQuery("#detail-big-bk").fadeIn();
		//Change small thumbnails
		jQuery(this).hide();
		jQuery("#detail-sm-fr").show();
		return false;
	});
	
	jQuery("#detail-sm-fr").click(function(){
		//Change big pictures
		jQuery("#detail-big-bk").hide();
		jQuery("#detail-big-fr").fadeIn();
		//Change small thumbnails
		jQuery(this).hide();
		jQuery("#detail-sm-bk").show();
		return false;
	});
}

function initSidebarPics() {
	
	jQuery("div.sidebar-pict ul a.pict-hold").hover(
		function(){
			jQuery(this).addClass('pict-rel');
			jQuery(this).children("span").addClass('hover');
		},
		function(){
			jQuery(this).children("span").removeClass('hover');
			jQuery(this).removeClass('pict-rel');
		}
	);
	
}

function initNewsFader(){
	
	//Show lightbox
	jQuery("div.sidebar-pict ul a.pict-hold").click(function(){
		
		var imageSrc = jQuery(this).children('img').attr('src');
		var imageAlt = jQuery(this).children('img').attr('alt');
		var imageTitle = jQuery(this).children('img').attr('title');
		var imageCaption = jQuery(this).parents('li').find('p').text();
		
		jQuery('div.news-popup img.picture').attr('src', imageSrc);
		jQuery('div.news-popup img.picture').attr('alt', imageAlt);
		jQuery('div.news-popup img.picture').attr('title', imageTitle);
		jQuery('div.news-popup div.info p').html(imageCaption);

		var div = jQuery('div.news-popup');
		showFader();
		centerPopup();
		var width = jQuery('div.news-popup img.picture').width();
		
		var left = (jQuery(window).width() - width)/2;
		div.css({
			"left": left+'px',
			"width": width+'px',
			"visibility": "visible",
			"display": "none"
		});
		
		div.fadeIn();
		return false;
	});
	
	//Hide lightbox
	jQuery("div.news-popup div.info a.close").click(function(){
		jQuery('#fader').fadeOut();
		jQuery('div.news-popup').css('visibility','hidden');
		return false;
	});
}

function initResize(){
	//Lightbox move when resize window
	jQuery(window).resize(function(){
		if (jQuery('#fader').get(0)){
			fader_obj = jQuery('#fader');
			fader_obj.css('height', jQuery(document).height()+'px');
			fader_obj.css('width', jQuery('body').width()+'px');
			
			centerPopup();

			if (jQuery('div.news-popup').css('display') == 'block'){
				div = jQuery('div.news-popup');
				var ww = jQuery(window).width();
				if(div.width > ww){
					var pleft = 0;
				}
				else if((ww - div.width()) < 0){
					var pleft = 0;
				}
				else{
					var pleft = (ww - div.width())/2;
				}
				div.css('left',pleft+'px');
			}
			
			if (jQuery('div.clothing-popup').css('display') == 'block'){
				div = jQuery('div.clothing-popup');
				var ww = jQuery(window).width();
				if(div.width > ww){
					var pleft = 0;
				}
				else if((ww - div.width()) < 0){
					var pleft = 0;
				}
				else{
					var pleft = (ww - div.width())/2;
				}
				div.css('left',pleft+'px');
			}
		}
	});
}

function showFader(){
	
	if (!jQuery('#fader').get(0)){
		fader_html = '<div id="fader" style="background: #000000 none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; visibility: visible;  position: absolute; left: 0pt; top: 0pt; display: none; "> </div>';		
		jQuery('.allpage').after(fader_html);
	}
	
	fader_obj = jQuery('#fader');
	fader_obj.css('opacity', 0.7);
	fader_obj.css('height', jQuery(document).height()+'px');
	fader_obj.css('width', jQuery('body').width()+'px');
	fader_obj.show();
}

function initCustomSelect(){
	jQuery('div.select a.button').click(function(){
		jQuery(this).parents('div.select').find('ul').slideToggle("slow");
	});
	jQuery('div.select ul a').click(function(e){
		e.preventDefault();
		var curValue = jQuery(this).text();
		jQuery(this).parents('div.select').find('input').attr('value',curValue);
		jQuery(this).parents('div.select').find('a.button').html(curValue);
		jQuery(this).parents('div.select').find('ul').slideToggle("slow");
		return false;
	});
}

function flashVersion(){
	var d, n = navigator, m, f = 'Shockwave Flash';
	if((m = n.mimeTypes) && (m = m["application/x-shockwave-flash"]) && m.enabledPlugin && (n = n.plugins) && n[f]) {d = n[f].description}
	else if (window.ActiveXObject) { try { d = (new ActiveXObject((f+'.'+f).replace(/ /g,''))).GetVariable('$version');} catch (e) {}} 
	return d ? d.replace(/\D+/,'').split(/\D+/) : [0,0];
};


function initHomeFlash(){
	if (jQuery('div.homepage').get(0)){
		if (flashVersion()[0] >= 9 ) {
			jQuery('div.home-warnings').css('display', 'none');
			jQuery('div#homeflash').css('display', 'block');
			jQuery('div.homepage').css('background-image', 'none');
			var so = new SWFObject("mizuno.swf", "Amber", "910", "530", "9", "#000000");
			so.addParam("wmode", "transparent");
			so.addVariable("content", "xml/mizunomenu.xml");
			so.write("homeflash");
		} else {
			jQuery('div.homepage div.warning-java').css('display', 'none');
			jQuery('div.homepage div.warning-flash').css('display', 'block');
		}
	}
}

function initDropDownAthletes(){
	var na;
	jQuery('div.subextra-drop > ul > li > a').hover(
		function(){
			var li = jQuery(this).parent();
			if ( jQuery(li).children('div.drop:visible').get(0) ){
				return;//jQuery(li).parent('ul').children().children('div.drop').hide('fast');
			} else {
				//jQuery(li).parent('ul').children().children('div.drop').hide('fast');
				jQuery('div.subextra-drop div.drop').hide('fast');
				jQuery(li).children('div.drop').show('fast');
			}
		},
		function(){
			return;
		}
	);
	
	jQuery('div.subextra-drop > ul').hover(
		function(){
			if ( na != null ) clearTimeout(na);
			return false;
		},
		function(){
			drop_par = this;
			na = setTimeout("hideDrop()", 2000);
		}
	);
}
var drop_par;
function hideDrop(){
	jQuery(drop_par).find('div.drop').hide('fast');
	return;
}