var imgBorder_botton = function () {
	$("#center .bordered_botton").each(function() {
		var thisAlign = $(this).attr("align") || $(this).css("float");
		var thisAlignCss = "";
		
		switch (thisAlign) {
			case "left":
				thisAlignCss = "float: left; ";
				break;
			
			case "right":
				thisAlignCss = "float: right; ";
				break;
			
			case "center":
				thisAlignCss = "float: none; margin-left: auto; margin-right: auto; ";
				break;
			
			default:
				thisAlignCss = "float: left; ";
				break;
		}
		
		$(this).removeClass("bordered_botton");
		var paddingWidth = $(this).width() + 10;
		
		var thisTitle = ($(this).attr("title") != "") ? ("<div class=\"img-title\" style=\"padding-left: " + paddingWidth + "px\">" + $(this).attr("title").replace(" | ", "<br/>") + "</div>") : "";
		$(this).attr("title", "");
		
		var thisHTML = $($("<div></div>").html($(this).clone())).html();
		var thisWidth = '100%';
		
		$(this).replaceWith(
			"<br clear=\"all\"/>" +
			"<div class=\"img\" style=\"" + thisAlignCss + thisWidth + "\">" +
				"<div class=\"img-border\">" +
					"<div class=\"img-border-t\"></div>" +
					"<div class=\"img-border-tr\"></div>" +
					"<div class=\"img-border-r\"></div>" +
					"<div class=\"img-border-br\"></div>" +
					"<div class=\"img-border-b\"></div>" +
					"<div class=\"img-border-bl\"></div>" +
					"<div class=\"img-border-l\"></div>" +
					"<div class=\"img-border-tl\"></div>" +
					"<div class=\"img-content_botton\">" +
						thisHTML +
						thisTitle +
					"</div>" +
				"</div>" +
			"</div>"
		);
	});
};

var imgBorder = function () {
	$("#center .bordered").each(function() {
		var thisAlign = $(this).attr("align") || $(this).css("float");
		var thisAlignCss = "";
		
		switch (thisAlign) {
			case "left":
				thisAlignCss = "float: left; ";
				break;
			
			case "right":
				thisAlignCss = "float: right; ";
				break;
			
			case "center":
				thisAlignCss = "float: none; margin-left: auto; margin-right: auto; ";
				break;
				
      case "middle":
				thisAlignCss = "float: none; margin-left: auto; margin-right: auto; ";
				break;
			
			default:
				thisAlignCss = "float: left; ";
				break;
		}
		
		$(this).css("float", "none");
		$(this).removeClass("bordered");
		
		var thisTitle = ($(this).attr("title") != "") ? ("<div class=\"img-title\">" + $(this).attr("title").replace(" | ", "<br/>") + "</div>") : "";
		$(this).attr("title", "");
		
		var thisHTML = $($("<div></div>").html($(this).clone())).html();
		var thisWidth = ($(this).is("img")) ? ("width: " + ($(this).width() + 2) + "px;") : "";
		
		$(this).replaceWith(
			"<br clear=\"all\"/>" +
			"<div class=\"img\" style=\"" + thisAlignCss + thisWidth + "\">" +
				"<div class=\"img-border\">" +
					"<div class=\"img-border-t\"></div>" +
					"<div class=\"img-border-tr\"></div>" +
					"<div class=\"img-border-r\"></div>" +
					"<div class=\"img-border-br\"></div>" +
					"<div class=\"img-border-b\"></div>" +
					"<div class=\"img-border-bl\"></div>" +
					"<div class=\"img-border-l\"></div>" +
					"<div class=\"img-border-tl\"></div>" +
					"<div class=\"img-content\">" +
						thisHTML +
						thisTitle +
					"</div>" +
				"</div>" +
			"</div>"
		);
	});
	
	$("#center h2").each(function() {
		$(this).wrap("<div class=\"h2\"></div>");
		
		var lineWidth = $(this).parent().width() - $(this).width() - parseInt($(this).css("margin-right")) - 1;
		var lineHeight = $(this).height() + parseInt($(this).css("margin-top"), 10) - 4;
		
		$("<div class=\"line\"></div>").width(lineWidth).height(lineHeight).insertAfter(this);
	});
};

var scrollThumbsVer = function() {
	var sh = $("#scroller").height();
	var th = $("#scroller ul").height();
	
	if (th > sh) {
		var tt = parseInt($("#scroller ul").css("top"), 10);
		var lh = $("#scroller ul li").outerHeight({"margin" : true});
		
		if (tt < -lh) {
			$("#scroller ul").append($($("#scroller ul li")[0]));
			$("#scroller ul").css("top", tt + lh - 1 + "px");
			
		} else {
			$("#scroller ul").css("top", tt - 1 + "px");
		}
	}
};

$(window).load(function() {
	if (!$.browser.msie || ($.browser.msie && parseInt($.browser.version, 10) > 6)) {
		imgBorder();
		imgBorder_botton();
	}
	
	//Scroller
	$("#scroller ul a").each(function() {
		$(this).attr("rel", "scroll-photos");
		
	}).fancybox({
		"zoomOpacity" : true,
		"overlayShow" : true,
		"zoomSpeedIn" : 500,
		"zoomSpeedOut" : 500,
		"titlePosition"  : "inside",
		"hideOnContentClick" : true
	});
	
	$("a.fancy").fancybox({
		"zoomOpacity" : true,
		"overlayShow" : true,
		"zoomSpeedIn" : 500,
		"zoomSpeedOut" : 500,
		"titlePosition"  : "inside",
		"hideOnContentClick" : true
	});
	
	var scrollerWidth = $("#scroller").width();
	
	if ($.browser.msie) {
		$("#scroller ul").css("left", (scrollerWidth - $("#scroller ul").width()) + "px");
	}
	
	scrollVerTimer = window.setInterval("scrollThumbsVer();", 50);
	//
	
	$("#center div.info").each(function() {
		var div = $(this);
		var span = $("<span>" + $(div).html() + "</span>");
		
		$(div).html(span);
		
		var hDelta = $(div).height() - $(span).height();
		$(span).css("padding-top", (hDelta < 0) ? 0 : (hDelta / 2));
	});
	
	//swfobject.embedSWF("images/pr_en/swf_head.swf", "en-page-header-img", "1000", "297", "9.0.0");
	swfobject.embedSWF("images/pr_en/r_banner.swf", "en-r-banner", "191", "281", "9.0.0");
	swfobject.embedSWF(banner_flash, "header-img", "586", "296", "9.0.0");
});


