jQuery(function ($){
	
	// 3column layout
	(function column3 () {
			$(".column3 li:last-child").css("margin-right", 0);
		})();
	
	// RollOver
	(function navRollOver (){
			var rolloverNav = $(".global a, #side ul li a, #staffPlace a, .headerSwitch li img, .designTopics li a, .example_archive li img, a.over img, ul.topTopics li a img, section.soyblog div#soyblogBoxL a img");
	
			rolloverNav.each(function(index, element) {
				$(this).hover(function (){
						$(this).stop().fadeTo(100,0.5);
					}, function (){
						$(this).stop().fadeTo(100,1);
					});
			});
		})();
	
	// printBtn
	(function doPrint (){
			$(".headerSwitch li img[title='print']").bind("click", function (){
					print();
				})
		})();
	
	// fontsize change
	(function fontSizeChanger (){
			$(".headerSwitch li img:not([title='print'])").bind("click", function (){
					var size = $(this).attr("title"),
							main = $("#main, footer .footerContent");
					switch (size) {
						case "fant_s" :
						main.css({"font-size": 10});
						break;
						case "fant_m" :
						main.css({"font-size": 12});
						break;
						case "fant_l" :
						main.css({"font-size": 14});
						break;
					}
				})
		})();
		
	// example list margin
	(function exampleListMargin (){
			if($("body").hasClass("example")) {
				var exBox = $(".example_archive");
				exBox.find("li").each(function(index, element) {
					var i = $(this).index();
					if((i+1)%4 == 0 && i!==0) {
						$(this).css("margin-right", 0);
					}
				});
			}
		})();
	
	// detailThumbImage margin
	(function detailThumbImageMargin (){
			if($("body").hasClass("example")) {
				var exBox = $(".detailThumbImage");
				exBox.find("li").each(function(index, element) {
					var i = $(this).index();
					if((i+1)%3 == 0 && i!==0) {
						$(this).css("margin-right", 0);
					}
				});
			}
		})();
	
	// designTopics margin
	(function detailThumbImageMargin (){
			if($("body").hasClass("example")) {
				var exBox = $(".designTopics");
				exBox.find("li").each(function(index, element) {
					var i = $(this).index();
					if((i+1)%5 == 0 && i!==0) {
						$(this).css("margin-right", 0);
					}
				});
			}
		})();
	
	(function exDetailImageSlider () {
		if($("body").hasClass("example")) {
			var ul = $(".example #main .example_detail ul.imageSwitcher"),
					sw1 = ul.find("li#sw_img"),
					sw2 = ul.find("li#sw_plan"),
					folder = $("#detailImageArea .imageFolder"),
					targetY = 0;
			
			sw1.bind("click", function (){
				if(targetY != 0) {
					targetY = 0;
					ul.css("background-position", "left");
					doSlide();
					}
				});
			
			sw2.bind("click", function (){
				if(targetY != -375) {
					targetY = -375;
					ul.css("background-position", "right");
					doSlide();
					}
				});
			
			function doSlide () {
				folder.animate({"margin-top": targetY}, 100);
			}
			
			}
		})();
	
	//DesignTopics's view
	$("ul.designTopicsLi li, ul.topTopics li").each(function(i){
		i = i+1;
		$(this).addClass("topics"+i);
		});

	//top DesignTopics
	(function examples () {
		var maxH = 0, len = $("ul.topTopics li").size(), counts = 0;
		$("ul.topTopics li").each(function (){
			var boxes = $(this).hide();
			var img = $(this).find("figure img").get(0);
			$(img).attr("src", $(img).attr("src")+"?"+new Date().getTime());
			img.onload = function () {
				var thisH = boxes.height();
				//console.log(boxes.height());
				if(maxH < thisH) maxH = thisH;
				counts++;
				if(counts == len) {
					//console.log("COMPLETE"+counts);
					$("p#topIcon").fadeOut(500,function(){
						$("div#topLoading").css({"height":"auto"});
						$("ul.topTopics li").css({"height":maxH}).fadeIn(500);
					});
				}
			}
		});
		//
	})();
	
	(function formClient() {
		var client = $("section.fromClient");
		client.find("p:empty").parent().parent().remove();
	})();
	
	/*var maxH = 0, len = $("ul.topTopics li").size(), counts = 0;
	$("ul.topTopics li").each(function (){
		var boxes = $(this);
		var img = $(this).find("figure img").get(0);
		$(img).attr("src", $(img).attr("src")+"?"+new Date().getTime());
		img.onload = function () {
			var thisH = boxes.height();
			if(maxH < thisH) maxH = thisH;
			counts++;
			if(counts == len) {
				$("ul.topTopics li").css({"height":maxH});
			}
		}
	});*/
	
	
	
	
	
	
	});
