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 () {
	
	if (movie_fullscreen === true) {
		
		// Movie
		$("#flash_movie").css("width", "936px");
		$("#flash_movie").css("height", "494px");
		$("#flash_movie").css("left", "31px");
		$("#flash_movie").css("top", "73px");
		$("#flash_movie").css("position", "absolute");
		
		// Button
		$("#btn_movie_on").css("display","none");
		$("#btn_movie_off").css("display","block");
		
		// Status
		movie_fullscreen = false;
		
	} 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");
		
		// Status
		movie_fullscreen = true;
	}
}

$(document).ready( function () {

	if (top.frames.length!=0) top.location=self.document.location;
	
	/**
	 * Movie
	 */

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

	$("#flash_movie img.btn_movie").click(function(){ set_movie_screen(); });
	
	/**
	 * 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").mouseleave(function(){ $("#collection_start").css("background-position","0 0"); });	
	
	/**
	 * Collection gallery
	 */	

	var ccat = new Object();
	ccat.size_difference = 10;
	ccat.top_difference = 20;
	ccat.speed = 700;
	ccat.easing = "easeOutElastic";
	ccat.el_settings = new Array;
	
	/**
	// Start
	$("#collection_category a").each(function(index, item) {
		
		var unique_id = $(this).parents("div:first").attr("class");
		var el_image = $(this).parents("div:first").children("img.image");
		var el_label = $(this).parents("div:first").children("img.label");
		
		// Get current width of image
		var current_width = parseInt(el_image.css("width"));
		
		// Get current top position of label
		var current_top = parseInt(el_label.css("top"));
		
		// Add to array so we can use these start settings later on
		ccat.el_settings[unique_id] = new Array;
		ccat.el_settings[unique_id]["width"] = current_width;
		ccat.el_settings[unique_id]["top"] = current_top;
	});
	*/
	
	// Mouse enter
	$("#collection_category a").mouseenter(function(){

		var unique_id = $(this).parents("div:first").attr("class");
		var el_image = $(this).parents("div:first").children("img.image");
		var el_label = $(this).parents("div:first").children("img.label");
		
		// Save this element
		var current_width = parseInt(el_image.width());
		var current_top = parseInt(el_label.css("top"));

		// Add to array so we can use these start settings later on
		ccat.el_settings[unique_id] = new Array;
		ccat.el_settings[unique_id]["width"] = current_width;
		ccat.el_settings[unique_id]["top"] = current_top;

		if (ccat.el_settings[unique_id]["width"] > 0) {
			
			// Get current width of image
			var current_width = parseInt(ccat.el_settings[unique_id]["width"]);
			var new_width = current_width+ccat.size_difference;
			
			// Get current top position of label
			var current_top = parseInt(ccat.el_settings[unique_id]["top"]);
			var new_top = current_top+ccat.top_difference;
			
			el_image.stop().animate({"width":new_width+"px"}, ccat.speed, ccat.easing);
			el_label.stop().animate({"top":new_top+"px"}, ccat.speed, ccat.easing);
		}
	});
	
	// Mouse leave
	$("#collection_category a").mouseleave(function(){

		var unique_id = $(this).parents("div:first").attr("class");
		var el_image = $(this).parents("div:first").children("img.image");	
		var el_label = $(this).parents("div:first").children("img.label");
		
		if (ccat.el_settings[unique_id]["width"] > 0) {
		
			el_image.stop().animate({"width":ccat.el_settings[unique_id]["width"]+"px"}, ccat.speed, ccat.easing);
			el_label.stop().animate({"top":ccat.el_settings[unique_id]["top"]+"px"}, ccat.speed, ccat.easing);
		}
	});
	
	/**
	 * Collection overview items
	 */
	
	if ($("#collection_overview .items .item_container img").length > 0) {
	
		var coi = new Object();
		coi.step_pos = 0;
		coi.row_count = 0;
		coi.current_row = 0;
		coi.max_row = 0;
		coi.min_row = 0;
		coi.speed = 500;
		coi.easing = "easeOutBack";
		coi.product_count = $("#collection_overview .items .item_container img").length;
		
		// Determine rows
		$("#collection_overview .items .item_container br").each(function(index, item) {
			
			coi.row_count++;
		});
		
		// Max row
		coi.max_row = coi.row_count;
		
		// Determine row height for step pos
		coi.step_pos = parseInt($("#collection_overview .items .item_container img").height());

		// Determine selected item / row
		$("#collection_overview .items div.item_container a").each(function(index, item) {
			
			if ($(this).attr('class') == 'selected') {
				
				var pc = index/(coi.product_count/100);
				var row = parseInt(pc*(coi.row_count/100));
				
				coi.current_row = row-1;
			};
		});

		// Down
		$("#collection_overview img.arrow_down").click(function(){
			
			// Determine position of the item container
			coi.current_row++;
			
			if (coi.current_row <= coi.max_row) {

				new_top_margin = 0-parseInt(coi.step_pos * coi.current_row);
				
				// Set new position
				$("#collection_overview .items .item_container").stop().animate({"margin-top":new_top_margin+"px"}, coi.speed, coi.easing);
				
			} else {
				
				coi.current_row--;
			}
		});
		
		$("#collection_overview img.arrow_down").trigger('click');
		
		// Up
		$("#collection_overview img.arrow_up").click(function(){
			
			// Determine position of the item container
			coi.current_row--;
			
			if (coi.current_row >= coi.min_row) {
			
				new_top_margin = 0-parseInt(coi.step_pos * coi.current_row);
				
				// Set new position
				$("#collection_overview .items .item_container").stop().animate({"margin-top":new_top_margin+"px"}, coi.speed, coi.easing);
				
			} else {
				
				coi.current_row++;
			}
		});
	}
	
	/**
	 * Storelocator items
	 */
	
	if ($("#storelocator div.item").length > 0) {
	
		var sli = new Object();
		sli.step_pos = 130;
		sli.row_count = 0;
		sli.current_row = 0;
		sli.max_row = 0;
		sli.min_row = 0;
		sli.speed = 500;
		sli.easing = "easeOutBack";
		
		// Determine rows
		$("#storelocator div.item").each(function(index, item) {
			
			sli.row_count++;
		});
		
		// Max row
		sli.max_row = sli.row_count;
		
		// Down
		$("#storelocator img.arrow_down").click(function(){
			
			// Determine position of the item container
			sli.current_row++;
			
			if (sli.current_row <= sli.max_row) {
				
				new_top_margin = 0-parseInt(sli.step_pos * sli.current_row);
				
				// Set new position
				$("#storelocator .items .item_container").stop().animate({"margin-top":new_top_margin+"px"}, sli.speed, sli.easing);
				
			} else {
				
				sli.current_row--;
			}
		});
		
		// Up
		$("#storelocator img.arrow_up").click(function(){
			
			// Determine position of the item container
			sli.current_row--;
			
			if (sli.current_row >= sli.min_row) {
			
				new_top_margin = 0-parseInt(sli.step_pos * sli.current_row);
				
				// Set new position
				$("#storelocator .items .item_container").stop().animate({"margin-top":new_top_margin+"px"}, sli.speed, sli.easing);
				
			} else {
				
				sli.current_row++;
			}
		});
	}

	/**
	 * Info text
	 */
	
	if ($("#info div.item_container").length > 0) {
	
		var iti = new Object();
		iti.step_pos = 130;
		iti.row_count = 0;
		iti.current_row = 0;
		iti.max_row = 0;
		iti.min_row = 0;
		iti.speed = 500;
		iti.easing = "easeOutBack";
		
		// Determine rows
		var items_height = parseInt($("#info div.items").css("height"));
		iti.row_count = Math.round(items_height/iti.step_pos);
		
		// Max row
		iti.max_row = iti.row_count;
		
		// Down
		$("#info img.arrow_down").click(function(){
			
			// Determine position of the item container
			iti.current_row++;
			
			if (iti.current_row <= iti.max_row) {
				
				new_top_margin = 0-parseInt(iti.step_pos * iti.current_row);
				
				// Set new position
				$("#info .items .item_container").stop().animate({"margin-top":new_top_margin+"px"}, iti.speed, iti.easing);
				
			} else {
				
				iti.current_row--;
			}
		});
		
		// Up
		$("#info img.arrow_up").click(function(){
			
			// Determine position of the item container
			iti.current_row--;
			
			if (iti.current_row >= iti.min_row) {
			
				new_top_margin = 0-parseInt(iti.step_pos * iti.current_row);
				
				// Set new position
				$("#info .items .item_container").stop().animate({"margin-top":new_top_margin+"px"}, iti.speed, iti.easing);
				
			} else {
				
				iti.current_row++;
			}
		});
	}

	/**
	 * 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 });
});

