var useragent = navigator.userAgent.toLowerCase();
var browser = useragent.indexOf('msie') > 0 ? false : true;

function set_movie () {
	
	if (movie_src) {
	
		var params = {
			quality: "high",
			scale: "exactfit",
			wmode: "opaque",
			allowscriptaccess: "always",
			bgcolor: "#000000",
			allowFullScreen: "true"
		};
		
		var flashvars = {};
		var attributes = {};
		
		swfobject.embedSWF(movie_src, "flash_movie_content", "100%", "100%", "10.0.0", "", flashvars, params, attributes);
	}
}

function set_movie_screen () {
	
	// To inline
	if (movie_fullscreen === true) {
		
		// Movie
		$("#flash_movie").css("width", "934px");
		$("#flash_movie").css("height", "492px");
		$("#flash_movie").css("left", "31px");
		$("#flash_movie").css("top", "58px");
		$("#flash_movie").css("position", "absolute");
		
		// Button
		$("#btn_movie_on").css("display","none");
		$("#btn_movie_off").css("display","block");
		$("#download_poster_btn").css("display","block");
		
		// Status
		movie_fullscreen = false;
		
	// To full
	} else {
		
		// Movie
		if (browser) {
			
			var window_height = $(window).height();
			
		} else {
			
			var window_height = $(window).height()+16;
		}
		
		$("#flash_movie").css("width", "100%");
		$("#flash_movie").css("height", window_height+"px");
		$("#flash_movie").css("left", "0");
		$("#flash_movie").css("top", "0");
		$("#flash_movie").css("position", "fixed");
		
		// Button
		$("#btn_movie_on").css("display","block");
		$("#btn_movie_off").css("display","none");
		$("#download_poster_btn").css("display","none");

		// Status
		movie_fullscreen = true;
	}
}

function strpos (haystack, needle, offset) {
	
	var i = (haystack+'').indexOf(needle, (offset || 0));
	return i === -1 ? false : i;
}

$(document).ready( function () {
	
	//$(document)[0].oncontextmenu = function() {return false;}
	//$().bind("contextmenu",function(){return !1;});
	
	/**
	 * Movie
	 */

	if ($("#flash_movie").length > 0) {
	
		set_movie_screen ();
		set_movie ();
	}

	$("#flash_movie img.btn_movie").click(function(){ set_movie_screen(); });
	
	/**
	 * Zoom
	 */

	var options = {
	    zoomType: "standard",
	    lens:true,
	    title:false,
	    preloadImages: false,
	    alwaysOn: false,
	    xOffset: 45,
	    position: "left"
	};
	
	$(".zoom").jqzoom(options); 

	/**
	 * Start collection
	 */
	
	$("#collection_start a.boys").mouseenter(function(){ $("#collection_start").css("background-position","0 -489px"); });
	$("#collection_start a.girls").mouseenter(function(){ $("#collection_start").css("background-position","0 -978px"); });
	$("#collection_start a.footwear").mouseenter(function(){ $("#collection_start").css("background-position","0 -1467px"); });
	$("#collection_start a.underwear").mouseenter(function(){ $("#collection_start").css("background-position","0 -1956px"); });
	$("#collection_start a.accessoires").mouseenter(function(){ $("#collection_start").css("background-position","0 -2445px"); });
	$("#collection_start a.eyewear").mouseenter(function(){ $("#collection_start").css("background-position","0 -2934px"); });	
	
	/**
	 * Slideshow
	 */
	
	times = [2500,3000,4000,5000];
	var time_one = times[Math.floor(Math.random()*times.length)];
	var time_two = times[Math.floor(Math.random()*times.length)];
	
	$(".slideshow_left").cycle({ fx:"fade", speed:time_one });
	$(".slideshow_right").cycle({ fx:"fade", speed:time_two });
	
	/**
	 * Fancybox
	 */
	
	if ($("#header_slider_con a.header_link").length != 0) {
	
		$("#header_slider_con a.header_link").fancybox({
			"padding" : 0,
			"autoScale"	: false,
			"overlayOpacity" : 0.9,
			"overlayColor" : "#000000",
			"transitionIn" : "none",
			"transitionOut"	: "none",
			"width" : 650,
			"height" : 365,
			"titleShow" : false
			});
	}
	
	if ($("#product_video_link").length != 0) {
	
		$("#product_video_link").fancybox({
			"padding" : 0,
			"autoScale"	: true,
			"overlayOpacity" : 0.9,
			"overlayColor" : "#000000",
			"transitionIn" : "none",
			"transitionOut"	: "none",
			"autoDimensions": false,
			"width" : 712,
			"height" : 405,
			"titleShow" : false
			});
	}	
	
	/**
	 * Header slider items
	 */
	
	$(".header_item_con").hide().css({visibility: "visible"}).fadeIn("slow");
});

/**
 * Set product detail images
 */

active_image_id = 1;

function set_detail_image (id, type) {
	
	// Set active image id
	active_image_id = id;
	
	if ($(".images div#img_"+type+"_"+id).length == 0) {
		
		active_image_id = 1;
	}
	
	// First hide all images
	$(".images div.image_con").css("visibility", "hidden");
	
	// Then show the new image
	$(".images div#img_"+type+"_"+id).css("visibility", "visible");
}

/**
 * Set image zoom
 */

function set_image_zoom (id) {
	
	// First hide all images
	$(".images div.image_con").css("display", "none");
	
	// Then show the new image
	$(".images div#img"+id).css("display", "block");
}

/**
 * Set image type group
 */

function set_image_type_group (type) {
	
	// Front
	if (type == "front") {
		
		set_detail_image (active_image_id, "front");
		
		$("#colors_back").css("display", "none");
		$("#colors_front").css("display", "block");
		
	// Back
	} else if (type == "back") {
		
		set_detail_image (active_image_id, "back");
		
		$("#colors_back").css("display", "block");
		$("#colors_front").css("display", "none");		
	}
}

/**
 * Cufon
 */

/* Eurostile */
Cufon.replace(".footer_content h1", { fontFamily: "Eurostile LT Std" });
Cufon.replace("#top_nav li a", { fontFamily: "Eurostile LT Std" });
Cufon.replace("div#website_edition", { fontFamily: "Eurostile LT Std" });
Cufon.replace("#lang_nav li a", { fontFamily: "Eurostile LT Std" });
Cufon.replace("a.image_label", { fontFamily: "Eurostile LT Std" });
Cufon.replace(".category_left_nav li a", { fontFamily: "Eurostile LT Std" });
Cufon.replace(".category_top_nav li a", { fontFamily: "Eurostile LT Std", hover: true });
Cufon.replace("h1.category_header", { fontFamily: "Eurostile LT Std" });
Cufon.replace("div.page_header", { fontFamily: "Eurostile LT Std" });
Cufon.replace("#share_window div.title", { fontFamily: "Eurostile LT Std" });
Cufon.replace("#share_window div.subtitle", { fontFamily: "Eurostile LT Std" });
Cufon.replace("#share_window div.label", { fontFamily: "Eurostile LT Std" });
Cufon.replace("#share_window div.link a", { fontFamily: "Eurostile LT Std" });
Cufon.replace("a#return_btn", { fontFamily: "Eurostile LT Std" });
Cufon.replace("#catwalk div.title", { fontFamily: "Eurostile LT Std" });
Cufon.replace("#footwear_con div.swf_center_con_title", { fontFamily: "Eurostile LT Std" });

/* Times */
Cufon.replace("#result_items .item .label a.title strong", { fontFamily: "ITC Avant Garde Gothic Std Book" });
Cufon.replace("#result_items_small .item .label a.title strong", { fontFamily: "ITC Avant Garde Gothic Std Book" });
Cufon.replace("#product_group div.title", { fontFamily: "ITC Avant Garde Gothic Std Book" });
Cufon.replace("#footwear_con .image_thumbs div.title", { fontFamily: "ITC Avant Garde Gothic Std Book" });
Cufon.replace("#detail_con .options a", { fontFamily: "ITC Avant Garde Gothic Std Bold" });
Cufon.replace("#detail_con h2", { fontFamily: "ITC Avant Garde Gothic Std Book" });
Cufon.replace("#detail_con .actions a", { fontFamily: "ITC Avant Garde Gothic Std Bold" });


