function $S(id) { return document.getElementById(id); }

function alertEK(text) { alert(text); }

function commentSetEvent()
	{
	$("#postBox").css("display", "none");
	$(".postShowBT").click( function ()
		{
		$("#postBox").css("display", "");
		$("#postBox textarea[name='postText']").keypress(function (e) 
			{
			var ctrl = e.ctrlKey;
			if ( e.which == 13 && e.ctrlKey ) { $("#postBox").submit(); }
			} );
		} );
	
	$("#postBox").submit( function () {
		$("#postBox input[type='submit']").attr("disabled", "disabled");
		
		postText	= $("#postBox textarea[name='postText']").attr("value");
		contentType	= $("#postBox input[name='contentType']").attr("value");
		contentID	= $("#postBox input[name='contentID']").attr("value");
		
		$.post("/module/comments/ajax.save.php", { postText : postText, contentType: contentType, contentID: contentID, usdie: usdie }, function (data)
			{
			$("#postBox input[type='submit']").attr("disabled", "");
			if (data.error == "" && data.is_save)
				{
				$("#commentList tr:last").after(data.out);
				
				$("#postBox textarea[name='postText']").attr("value", "");
				$("#postBox").css("display", "none");
				}
				else
				{
				alert(data.error);
				}
			}, "json");
		
		return false;
		} );
	}

function setInputFieldAction(className)
	{
	var defValue = new Array();
	
	$("."+className+"[class!="+className+" null]").focus( function () {
		if ( !defValue[$(this).attr("name")] ) { defValue[$(this).attr("name")] = $(this).attr("value"); }
		if ( ($(this).attr("value") == "") || ($(this).attr("value") == defValue[$(this).attr("name")]) ) { $(this).attr("value", ""); $(this).css("color", "#333333"); }
	} );
	
	$("."+className+"[class!="+className+" null]").blur( function () {
		if ($(this).attr("value") == "")
			{
			$(this).attr("value", defValue[$(this).attr("name")] );
			$(this).css("color", "#C1C1C1");
			}
		} );
	
	$("."+className+"[class*=null]").css("color", "#333333");
	}

function recClickBT(el)
	{
	id = $(el).attr("id").replace("recBT","");
	if (id == 1) { subid = 2; } else { subid = 1; }
	
	$("#recBT" + id    ).removeClass("recBt"); $("#recBT" + id    ).addClass("recBtActive");
	$("#recBT" + subid ).addClass("recBt"); $("#recBT" + subid ).removeClass("recBtActive");
	
	$("#recC" + id   ).css("display", "");
	$("#recC" + subid).css("display", "none");
	}


function updateClock()
	{
	if ($("#clock").html())
		{
		ctime = $("#clock").html();
		
		gH = ctime.charAt(0) + ctime.charAt(1);
		gM = ctime.charAt(3) + ctime.charAt(4);
		gS = ctime.charAt(6) + ctime.charAt(7);
		
		//if (usdie == "16d4ef9") { alert( gH ); }
		
		var currentTime = new Date ( "Mon, 01 Dec 1970 " + gH + ":" + gM + ":" + gS ); // + " GMT+0500"
		
		var currentHours = currentTime.getHours ( );
		var currentMinutes = currentTime.getMinutes ( );
		var currentSeconds = currentTime.getSeconds ( );
		
		currentSeconds = currentSeconds + 1;
		if ( currentSeconds == 60 ) { currentMinutes = currentMinutes + 1; currentSeconds = 0; }
		if ( currentMinutes == 60 ) { currentHours = currentHours + 1; currentMinutes = 0; }
		
		currentHours   = ( currentHours < 10 ? "0" : "" ) + currentHours;
		currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
		currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
		
		$("#clock").html(currentHours + ":" + currentMinutes + ":" + currentSeconds);
		}
	}

function fontSize(to)
	{
	HS = 2; if ( to == 'down' ) { HS = -2; }
	NS = parseInt( $("td").css("font-size").replace("px","") );
	NNS = NS + HS;
	
	if (NNS > 16) { NNS = 16; }
	if (NNS < 8)  { NNS = 8; }
	
	$("td").css("font-size", NNS);
	/* fix for 'this' size set */
	}

function mainNewsGetAndSet( prefixN , id , rotate )
	{
	$.post("/template/base/ajax.image.php", { id: id } , function(data) {
		mainNewsSetText ( prefixN , data.image.name );
		mainNewsSetLink ( prefixN , id );
		mainNewsChange  ( prefixN , rotate , data.image.link , data.image.x , data.image.y );
		} , "json");
	}

function mainNewsSetLink ( prefixN , id )
	{
	$("."+prefixN+"Link").unbind('click').click( function () { showImage( id , true ); } );
	}

function mainNewsChange( prefixN , rotate , imgSrc , imgWidth , imgHeight )
	{
	if ( rotate == 'center' )
		{
		PosX = Math.round( ( imgWidth - 230 ) / 2 );
		PosY = Math.round( ( imgHeight - 157 ) / 2 );
		
		$("#"+prefixN+"Frame1").css("background-image", "url("+imgSrc+")");
		$("#"+prefixN+"Frame1").css( "background-position", "-" + PosX + "px -" + PosY + "px" );
		}
		else
		{
		$("#"+prefixN+"Frame2").css( "background-image"    , $("#"+prefixN+"Frame1").css("background-image")    );
		$("#"+prefixN+"Frame2").css( "background-position" , $("#"+prefixN+"Frame1").backgroundPosition() );
		
		$("#"+prefixN+"Frame1").css("background-image", "url("+imgSrc+")");
		toPosX = Math.round( ( imgWidth - 230 ) / 2 ); posY = Math.round( ( imgHeight - 157 ) / 2 );
		
		oldBackY = $("#"+prefixN+"Frame2").backgroundPosition().split(" "); oldBackY = oldBackY[1];
		
		if ( rotate == 'right' )
			{
			$("#"+prefixN+"Frame1").css("background-position", imgWidth+"px -"+posY+"px");
			
			$("#"+prefixN+"Frame1").animate({ backgroundPosition: '(-'+toPosX+'px -'+posY+'px)' });
			$("#"+prefixN+"Frame2").animate({ backgroundPosition: '(-300px '+oldBackY+')' });
			}
			else
			{
			$("#"+prefixN+"Frame1").css("background-position", "-"+imgWidth+"px -"+posY+"px");
			
			$("#"+prefixN+"Frame1").animate({ backgroundPosition: '(-'+toPosX+'px -'+posY+'px)' });
			$("#"+prefixN+"Frame2").animate({ backgroundPosition: '(300px '+oldBackY+')' });
			}
		}
	}

function mainNewsSetText( prefixN , text )
	{
	$("#"+prefixN+"Text").html ( text );
	
	//alert( $S(prefixN+"Text").offsetWidth );
	
	$("#"+prefixN+"TextBG").css("width", $S(prefixN+"Text").offsetWidth + 6 + "px" );
	$("#"+prefixN+"TextBG").css("height", $S(prefixN+"Text").offsetHeight + 6 + "px" );
	
	$("#"+prefixN+"TextBG img").css("width", $S(prefixN+"Text").offsetWidth + 6 + "px" );
	$("#"+prefixN+"TextBG img").css("height", $S(prefixN+"Text").offsetHeight + 6 + "px" );
	
	$("#"+prefixN+"Text").css("left", "3px" );
	$("#"+prefixN+"Text").css("top", "-" + $S(prefixN+"Text").offsetHeight - 5 + "px" );
	
	XH = parseInt( $S(prefixN+"TextTR").offsetHeight ) - 70;
	
	if ( XH > 0 )
		{
		$("#"+prefixN+"RotateLeft img").css("top", "-" + XH + "px"); $("#"+prefixN+"RotateRight img").css("top", "-" + XH + "px");
		}
		else
		{
		$("#"+prefixN+"RotateLeft img").css("top", "0px"); $("#"+prefixN+"RotateRight img").css("top", "-" + XH + "px");
		}
	}

function peopleShowInfo( show, id )
	{
	$.post("/sub/ajax.people.php", { show: show, id: id } , function(data) {
		showContent( data.out );
		} , "json");
	}

function feedbackShowInfo( text )
	{
	$.post("/sub/ajax.feedback.php", { send_text: text } , function(data) {
		showContent( data.out );
		} , "json");
	}

function strategyShowInfo( show, id )
	{
	$.post("/sub/ajax.strategy.php", { show: show, id: id } , function(data) {
		showContent( data.out );
		$("#fContent").css("height", "180px");
		$("#fContentIn").css("height", "180px").css("overflow", "visible");
		$("#fContentClose").css("margin-top", "-201px");
		posY = Math.round( ( $(window).height() / 2 ) - ( 180 / 2 ) + $(window).scrollTop() );
		$("#fContent").css("top", posY + "px");
		} , "json");
	}

function showContent( text )
	{
	closeContent();
	closeFill();
		
	showFill();
	
	posX = Math.round( ( $(window).width() / 2 ) - ( 500 / 2 ) );
	posY = Math.round( ( $(window).height() / 2 ) - ( 500 / 2 ) + $(window).scrollTop() );
	
	$("body").append("<div id='fContent'><div id='fContentIn'>"+text+"</div></div>");
	$("#fContent").css("width", 540 + 2 + "px")
				  .css("height", 500 + 2 + "px")
				  .css("position", "absolute")
				  .css("z-index", "2000")
				  .css("top", posY + "px")
				  .css("left", posX + "px")
				  .css("border", "1px solid #8F8F8D")
				  .css("background-color", "#FFFFFF")
				  .css("padding", "20px")
				  .css("padding-right", "0px");
	
	$("#fContentIn").css("overflow-y", "scroll")
					.css("height", 500 + 2 + "px")
					.css("padding-right", "20px");
	
	$("#fContent").append("<img src='/template/image/close.gif' width='15' height='15' alt='Закрыть' title='Закрыть' id='fContentClose'>");
	$("#fContentClose").css("position", "absolute")
					 .css("z-index", "2002")
					 .css("margin-left", "526px")
					 .css("margin-top", "-523px")
					 .css("cursor", "pointer")
					 .css("border", "1px solid #8F8F8D");
	if ( $.browser.msie ) { $("#fContentClose").css("margin-left", "504px"); }
	
	$("#fContentClose").click( function () { closeContent(); closeFill(); } );
	
	$("#fill").click( function () { closeContent(); closeFill(); } );
	}

function closeContent()
	{
	$("#fContent").remove();
	}

function showImageName ( text )
	{
	$("#fImageBTText").html ( text );
	
	$("#fImageBTTextBG").css("width", $S("fImageBTText").offsetWidth + 6 + "px" );
	$("#fImageBTTextBG").css("height", $S("fImageBTText").offsetHeight + 6 + "px" );
	
	$("#fImageBTTextBG img").css("width", $S("fImageBTText").offsetWidth + 6 + "px" );
	$("#fImageBTTextBG img").css("height", $S("fImageBTText").offsetHeight + 6 + "px" );
	
	$("#fImageBTText").css("left", "3px" );
	$("#fImageBTText").css("top", "-" + $S("fImageBTText").offsetHeight - 5 + "px" );
	}

function showImageSlideShow()
	{
	if ( fImageSlideShow )
		{
		setTimeout( "showImageSlideShowCAS()", 5000);
		}
	}

function showImageSlideShowCAS()
	{
	if ( fImageSlideShow )
		{
		$('#fImageBTRotateRight').click();
		showImageSlideShow();
		}
	}

fImageSlideShow = false;

function showImage( id , showBar )
	{
	if (typeof showBar == "undefined") { showBar = false; }
	
	$.post("/template/base/ajax.image.php", { id: id , fS : "600" } , function(data) {
		closeImage();
		closeFill();
		
		showFill();
		
		//data.image.x = 600;
		//data.image.y = 400;
		
		posX = Math.round( ( $(window).width() / 2 ) - ( data.image.x / 2 ) );
		posY = Math.round( ( $(window).height() / 2 ) - ( data.image.y / 2 ) + $(window).scrollTop() );
		//close
		
		$("body").append("<div id='fImage'><img src='" + data.image.link + "' id='fImageMain'></div>");
		$("#fImage").css("width", data.image.x + 2 + "px")
					.css("height", data.image.y + 2 + "px")
					.css("position", "absolute")
					.css("z-index", "2000")
					.css("top", posY + "px")
					.css("left", posX + "px")
					.css("border", "1px solid #8F8F8D");
		
			$("#fImage").append("<table cellspacing='0' cellpadding='0' id='fImageBT' border='0'>\
									<tr valign='top' style='height: "+ Math.round(data.image.y / 2 ) +"px;' id='mainNewsTextTR'>\
										<td colspan='3' class='mailNewsLink fImageOR2'>\
											<div id='fImageBTTextBG'><img src='/template/image/mainNewsBG.png' width='1' height='1'></div>\
												<div id='fImageBTText'></div>\
											</td>\
										</tr>\
										<tr valign='top'>\
											<td width='1' id='fImageBTRotateLeft'><img src='/template/image/mainNewsLeft.png' width='19' height='22' alt='' title='' border='0'></td>\
											<td width='100%' class='mailNewsLink fImageOR2'>&nbsp;</td>\
											<td width='1' id='fImageBTRotateRight'><img src='/template/image/mainNewsRight.png' width='19' height='22' alt='' title='' border='0'></td>\
										</tr>\
									</table>");
			
			$("#fImageBT").css("width", data.image.x + 1 + "px")
						.css("height", data.image.y + "px")
						.css("position", "absolute")
						.css("z-index", "2001")
						.css("top", "0px")
						.css("left", "0px");
		if ( showBar )
			{
			$.post("/template/base/ajax.pnImage.php", { id: id } , function(data) {
				$("#fImageBTRotateLeft").click( function () { showImage( data.image.prevID , true ); } );
				$("#fImageBTRotateRight").click( function () { showImage( data.image.nextID , true ); } );
			} , "json");
			}
			else
			{
			$("#fImageBTRotateLeft").css("display", "none");
			$("#fImageBTRotateRight").css("display", "none");
			}
		
		showImageName( data.image.name );
		
		$("#fImageMain").css("width", data.image.x + "px")
						.css("height", data.image.y + "px")
						.css("border", "1px solid #FFFFFF");
		
		$("#fImage").append("<img src='/template/image/close.gif' width='15' height='15' alt='Закрыть' title='Закрыть' id='fImageClose'>");
		$("#fImageClose").css("position", "absolute")
						 .css("z-index", "2002")
						 .css("margin-left", "-25px")
						 .css("margin-top", "10px")
						 .css("cursor", "pointer")
						 .css("border", "1px solid #8F8F8D");
		$("#fImageClose").click( function () { fImageSlideShow = false; closeImage(); closeFill(); } );
		
		$("#fImage").append("<table cellspacing='0' cellpadding='0' id='fImageBar'><tr><td style='padding-left: 10px;'>"+data.image.info+"</td><td id='fImageSlide'>Слайд шоу <span>&bull;</span></td><td id='fImageOR'>Оригинал</td></tr></table>");
		$("#fImageBar").css("width", data.image.x + 4 + "px").css("height", "23px").css("background-color", "#FFFFFF").css("border", "1px solid #747474").css("border-top", "0px").css("position", "relative").css("left", "-1px");
		$("#fImageSlide").css("width", "100px").css("text-align", "center").css("cursor", "pointer");
		$("#fImageOR").css("width", "100px").css("text-align", "center").css("cursor", "pointer");
		
		$.post("/template/base/ajax.image.php", { id: id , fS : "original" } , function(data) {
			$("#fImageOR").click( function () { window.open(data.image.link,'page_id','resizable=no,top='+(100)+',left='+(100)+',width='+(data.image.x + 18)+',height='+(data.image.y + 18)+',location=no,status=no,scrollbars=no'); } );
			$(".fImageOR2").css("cursor", "pointer");
			$(".fImageOR2").click( function () { window.open(data.image.link,'page_id','resizable=no,top='+(100)+',left='+(100)+',width='+(data.image.x + 18)+',height='+(data.image.y + 18)+',location=no,status=no,scrollbars=no'); } );
			} , "json");
		
		if ( !showBar )
			{
			$("#fImageSlide").css("display", "none");
			}
			else
			{
			$("#fImageSlide").click( function () { if ( fImageSlideShow == false ) { fImageSlideShow = true; $("#fImageSlide span").css("color", "#00BD3A"); showImageSlideShow(); } else { fImageSlideShow = false; $("#fImageSlide span").css("color", "#747474"); } } );
			$("#fImageSlide span").css("position", "absolute").css("font-size", "18px").css("margin-left", "5px");
			if ( fImageSlideShow == true ) { $("#fImageSlide span").css("color", "#00BD3A"); }
			}
		
		$("#fill").click( function () { fImageSlideShow = false; closeImage(); closeFill(); } );
		
		} , "json");
	}

function file_exists( file )
	{
	$.post("/template/base/ajax.fexists.php", { file: file } , function(data) {
		return data.exists;
		} );
	}

function closeImage()
	{
	$("#fImage").remove();
	}

function showFill()
	{
	winX = $(window).width();
	winY = $(window).height();
	
	marY = $(window).scrollTop();
	
	$("body").append("<img src='/template/image/fill.png' id='fill'>");
	$("#fill").css("width", winX + "px").css("height", winY + "px").css("position", "absolute").css("top", marY + "px").css("left", "0px").css("z-index", "1000");
	
	$(window).scroll( function () {
		fillChange();
		} );
	
	$(window).resize(function() {
		fillChange();
		} );
	}

function fillChange()
	{
	winX = $(window).width();
	winY = $(window).height();
	$("#fill").css("width", winX + "px").css("height", winY + "px");
	
	marY = $(window).scrollTop();
	$("#fill").css("top", marY + "px");
	
	posX = Math.round( ( $(window).width() / 2 ) - ( parseInt( $("#fImage").css("width") ) / 2 ) + $(window).scrollLeft() );
	posY = Math.round( ( $(window).height() / 2 ) - ( parseInt( $("#fImage").css("height") ) / 2 ) + $(window).scrollTop() );
	
	if ( $("#fImage") ) { $("#fImage").css("left", posX + "px").css("top", posY + "px"); }
	if ( $("#fContent") ) { $("#fContent").css("left", posX + "px").css("top", posY + "px"); }
	}

function closeFill()
	{
	$("#fill").remove();
	}
	
	

function gallerySetImage( id )
	{
	$.post("/template/base/ajax.image.php", { id: id } , function(data) {
		$("#photoImage").css("width", data.image.x + "px");
		$("#photoImage").css("height", data.image.y + "px");
		$("#photoImage").attr("src", data.image.link);
		} , "json");
	}

function gallerySetCenter( imgShowThis )
	{
	br = 4; if ( $.browser.msie ) { br = 7; }
	mTop = ( 100 + 5 + br ) * imgShowThis; // 100 img height
	mBar = Math.round( ( parseInt ( $("#bar").css("height") ) - 10) / 2 ) - 50; // 50 - half img height
	if ( $.browser.msie ) { mBar = mBar - 20; }
	mTop = mTop - mBar;
	
	//alert(mTop);
	//fixH = parseInt ( $("#bar div").css("height") ) - parseInt ( $("#bar").css("height") ) - 5;
	fixH = parseInt ( $("#bar div").attr("offsetHeight") ) - parseInt ( $("#bar").css("height") ) - 5;
	//alert ( $("#bar div").css("height") );
	//alert ( $("#bar div").attr("offsetHeight") );
	//alert ( $("#bar").css("height") );
	
	if ( mTop < 0 ) { mTop = 0; }
	if ( mTop > fixH ) { mTop = fixH; }
	
	$("#bar div").css("margin-top", "-" + mTop + "px");
	}

function getArrayKey( aR , val )
	{
	key = false;
	for (a = 0; a <= aR.length; a++)
		{
		if ( aR[a] == val ) { key = a; }
		}
	
	return key;
	}
	

function showVideoWindow( videoID, showOther )
	{
	closeContent();
	closeFill();
	
	showFill();
	
	$.post("/sub/ajax.video.show.php", { id: videoID } , function(data)
		{
		posX = Math.round( ( $(window).width() / 2 ) - ( 640 / 2 ) );
		posY = Math.round( ( $(window).height() / 2 ) - ( 480 / 2 ) + $(window).scrollTop() );
		
		$("body").append("<div id='fContent'><div id='fContentIn'>"+data.out+"</div></div>");
		
		$("#fContent").css("width", 640 + 0 + "px")
					.css("height", 480 + 0 + "px")
					.css("position", "absolute")
					.css("z-index", "2000")
					.css("top", posY + "px")
					.css("left", posX + "px")
					.css("border", "1px solid #8F8F8D")
					.css("background-color", "#FFFFFF");
		
		$("#fContent").append("<img src='/template/image/close.gif' width='15' height='15' alt='Закрыть' title='Закрыть' id='fContentClose'>");
		$("#fContentClose").css("position", "absolute")
						   .css("z-index", "2002")
						   .css("margin-left", "613px")
						   .css("margin-top", "-468px")
						   .css("cursor", "pointer")
						   .css("border", "1px solid #8F8F8D");
		//if ( $.browser.msie ) { $("#fContentClose").css("margin-left", "504px"); }
		
		$("#fContentClose").click( function () { closeContent(); closeFill(); } );
		
		$("#fill").click( function () { closeContent(); closeFill(); } );
		} , "json");
	}
	
	
function showSendLink()
	{
	windowOpen();
	
	title = "Отправить ссылку другу";
	tpl = "/template/module/sendLink.html";
	
	if ( tpl )
		{
		$("#popup_title").text(title);
		$("#popup_message").load( tpl , "" , function ()
			{
			$("#buttonSend").click( function () { showSend(); } );
			$("#buttonClose").click( function() { windowClose(); return false; } );
			
			if (usdie != 'die') { $("#sendCap").css("display", "none"); }
			} );
		}
	}
	
function showSend()
	{
	$("#sendError").html(""); SError = "";
	
	sEmail = $("#sendEmail").attr("value");
	sName = $("#sendName").attr("value");
	sCode = $("#sendCode").attr("value");
	
	sFromEmail = $("#sendFromEmail").attr("value");
	sCMT = $("#sendCMT").attr("value");
	
	linkSRC = document.location.href;

	if ( sEmail == "" ) { SError += "Введите Email друга<br>"; }
	if ( ( sEmail != "" ) && ( !is_email(sEmail) ) ) { SError += "Проверьте правильность Email'а друга<br>"; }
	if ( sName == "" ) { SError += "Введите Ваше имя<br>"; }
	if ( usdie == 'die' ) { if ( sCode == "" ) { SError += "Введите код подтверждения<br>"; } }
	
	if (SError != "")
		{
		$("#sendError").html(SError);
		}
		else
		{
		$.post("/sub/ajax.sendLink.php", { sendEmail: sEmail, sendName: sName, sendCode: sCode, sendFromEmail: sFromEmail, sendCMT: sCMT, linkSRC: linkSRC } , function(data) {
			if ( data.error != "" )
				{
				$("#sendError").html(data.error);
				}
				else
				{
				alertEK("Ссылка отправлена адресату");
				}
			} , "json");
		}
	}
	
function is_email(mail)
	{
	if( mail ){ if(mail.match(/^[A-Za-z0-9\.\-\_]{1,32}\@[A-Za-z0-9\.\-\_]{1,32}\.[a-zA-Z]{2,6}$/)) {return true;} else {return false;} }else{ return false; }
	}
	

function previewchangevideo( videoID , elv )
	{
	vX = $("#"+elv+videoID).width();
	vY = $("#"+elv+videoID).height();
	
	//alert( videoID );
	//$("#"+elv+videoID).replaceWith( videoID );
	
	$.post("/template/base/ajax.video.php", { id: videoID } , function(data)
		{
		var flashvars = { 'file': data.video , 'autostart': 'true', 'showReplayButton': 'true', 'showBigPlayButton': 'true' };
		var params = { 'allowfullscreen': 'true', 'allowscriptaccess': 'always', 'type': 'application/x-shockwave-flash', 'wmode': 'transparent' };
		var attributes = {};
		swfobject.embedSWF('/template/swf/player3.swf', elv+videoID, vX, vY, '9', '#FFFFFF', flashvars, params, attributes);
		} , "json");
	}

function altExFile( id )
	{
	
	}

$(document).ready( function() {
$(".altExFile").click( function() {
	exID = $(this).attr("id").replace("f", "");
	$.get("/sub/ajax.exfile.php", { id: exID } , function(data) { window.location = data.out; }, "json");
	return false;
	} );
} );

(function($) {
	jQuery.fn.backgroundPosition = function() {
	var p = $(this).css('background-position');
	if(p == undefined) return $(this).css('background-position-x') + ' ' + $(this).css('background-position-y');
	else return p;
	};
})(jQuery);

(function($) {
	
	function toArray(strg){
		strg = strg.replace(/left|top/g,'0px');
		strg = strg.replace(/right|bottom/g,'100%');
		strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
		var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
		return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
	}
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (!fx.bgPosReady) {
                var start = $.curCSS(fx.elem,'backgroundPosition');
				if(!start){
					return false;
				}
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
				fx.bgPosReady = true;
			}
			var nowPosX = [];
			nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
			nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
			fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
        }
	});
})(jQuery);

$(document).ready( function () {
	updateClock();
	setInterval('updateClock()', 1000 );
} );

$(document).ready( function () {
	$("#fontSizer a:last").click( function () { fontSize("up"); return false; } );
	$("#fontSizer a:first" ).click( function () { fontSize("down"); return false; } );
	$(".sentable a").click( function () { showSendLink(); return false; } );
} );

$(document).ready( function () {
if ( $.browser.msie )
	{
	$(".imgHover").mouseover( function() { $(this).css("border", "1px solid #23A1FF"); } ).mouseout( function() { $(this).css("border", "1px solid #FFFFFF"); } );
	};
} );

$(document).ready( function () {
	$(".beautyBt").click( function () {
		$(".header2-beauty > div").remove();
		
		forH2B = $(this).attr("id").replace("bg","");
		
		url = "/template/image/bn/"+$(this).attr("id")+".jpg";
		
		width = $(".header2-beauty > table").width();
		
		$(".header2-beauty").append("<div style='display: none;'></div>");
		$(".header2-beauty > div").css("width", width + "px").css("height", "206px").css("z-index", "990").css("background-position", "center").css("background-repeat", "no-repeat");
		
		$(".header2-beauty > table").css("width", width + "px" ).css("position", "absolute").css("margin-top", "174px").css("z-index", "1000");
		
		$(".header2-beauty > div").css("background-image", "url("+url+")");
		$(".header2-beauty > div").fadeIn("slow", function () {
			$(".header2-beauty").css("background-image", "url("+url+")");
			$(".header2-beauty > div").remove();
			$(".header2-beauty > table").css("width", "100%").css("position", "static").css("margin-top", "0px");
			
			$(".header2-beauty table").before("<div class='H2B'>&nbsp;</div>");
			setH2BLink( forH2B );
			} );
		
		$(".beautyBt").removeClass("bbtOn"); $(".beautyBt").addClass("bbtOff");
		
		$(this).removeClass("bbtOff"); $(this).addClass("bbtOn");
		} );
	
	H2Hover = 0;
	
	/*
	$(".beautyBt").mouseover( function () {
		if ( $(this).attr("class") == "beautyBt bbtOff" )
			{
			H2Hover = $(this).attr("id");
			$("#" + H2Hover).removeClass("bbtOff");
			$("#" + H2Hover).addClass("bbtOn");
			
			$("#" + H2Hover).css("background-position", "right 5px").css("height", "27px");
			$("#" + H2Hover + " div").css("padding", "4px 21px 5px 21px").css("background-position", "left 0px");
			}
	} );
	
	$(".beautyBt").mouseout( function () {
		if ( $(this).attr("class") == "beautyBt bbtOn" )
			{
			if ( H2Hover == $(this).attr("id") )
				{
				$("#" + H2Hover).css("background-position", "right top").css("height", "32px");
				$("#" + H2Hover + " div").css("padding", "7px 21px 5px 21px").css("background-position", "left bottom");
				
				$("#" + H2Hover).removeClass("bbtOn");
				$("#" + H2Hover).addClass("bbtOff");
				}
			}
	} );
	*/
	
	setH2BLink(getH2Active());
	
	$(".header2-beauty").mouseover( function () { H2S = false; } );
	$(".header2-beauty").mouseout ( function () { H2S = true;  } );
} );

function setH2BLink(id)
	{
	XL = $("#H2BLink" + id).html();
	$(".H2B").click( function() { window.location = XL; } );
	}

H2W = new Array();
H2S = true;
H2Max = 2;

$(document).ready( function () {
	setTimeout( "setH2Timer()", 5000);
} );

function getH2Active()
	{
	active = false;
	
	for (a = 1; a <= H2Max; a++)
		{
		if ( $("#bg" + a).attr("class") == "beautyBt bbtOn" ) { active = a; }
		}
	
	return active;
	}

function setH2Active( nowID )
	{
	if ( H2S )
		{
		nowID = nowID + 1; 
		if ( nowID > H2Max ) { nowID = 1; }
		$("#bg" + nowID).click();
		}
	}

function setH2Timer()
	{
	nowID = getH2Active();
	setH2Active( nowID );
	setTimeout( "setH2Timer()", 7000);
	}

function bannerActiveChange(bannerFrom, bannerTO, bannerWhere)
	{
	$.post("/sub/ajax.bannerActive.php", { bannerID: bannerTO } , function(data) {
		if ( data.banner != "" )
			{
			$("#"+bannerWhere).after("<div id='"+bannerWhere+"_new'></div>");
			
			
			newB_width = $("#"+bannerWhere).css("width");   $("#"+bannerWhere+"_new").css("width", newB_width);
			newB_height = $("#"+bannerWhere).height(); $("#"+bannerWhere+"_new").css("height", newB_height);
			
			if ( $.browser.msie ) { newB_height = newB_height + 2; }
			$("#"+bannerWhere+"_new").css("position", "absolute").css("margin-top", "-"+( newB_height )+"px");
			
			$("#"+bannerWhere+"_new").html(data.banner).css("display", "none");
			
			$("#"+bannerWhere+"_new").fadeIn("slow", function () {
				$("#"+bannerWhere).remove();
				$("#"+bannerWhere+"_new").css("position", "static").css("margin-top", "0px");
				$("#"+bannerWhere+"_new").attr("id", bannerWhere);
			} );
			
			setTimeout( "bannerActiveChange("+bannerTO+", "+bannerFrom+", '"+bannerWhere+"')", 7000);
			}
		} , "json");
	}

/* H2B */

function H2Binit()
	{
	/* generate, preload image array */
	imgH2B_v3_pre = new Array();
	for( ai = 0; ai < H2B_v3_img.length; ai ++)
		{
		imgH2B_v3_pre[ai] = new Image;
		if (H2B_v3_img[ai] != "") { imgH2B_v3_pre[ai].src = H2B_v3_img[ai]; }
		}
	
	/* set default */
	setH2B_v3_link(H2B_v3_lnk[H2B_v3_Active]);
	setH2B_v3_subline( H2B_v3_Active );
	
	/* set event */
	$(".H2B_v3_Link").mouseover( function() {
		hid = $(this).attr("id").replace("H2B_v3_I", "");
		H2B_v3_S = false;
		setH2B_v3( hid , 'simple' );
	} );
	
	$(".H2B_v3_Link").mouseout( function() {
		hid = $(this).attr("id").replace("H2B_v3_I", "");
		H2B_v3_S = true;
		unsetH2B_v3( hid );
	} );
	
	$("#H2B_set").mouseover( function() { H2B_v3_S = false; } );
	$("#H2B_set").mouseout(  function() { H2B_v3_S = true; } );
	
	/* start auto change */
	setTimeout( 'setH2B_v3_next();', H2B_v3_changeTimer );
	}

function setH2B_v3( hid , changeType )
	{
	$(".H2B_v3_Link").css("background-color", "transparent").css("background-position", "10px 12px");
	$("#H2B_v3_I" + hid).css("background-color", "#0E5284").css("background-position", "-230px 11px");
	setH2B_v3_subline( hid );
	changeH2B_img( hid , changeType );
	setH2B_v3_link(H2B_v3_lnk[hid]);
	
	//clearTimeout(H2B_v3_timeout);
	H2B_v3_Active = hid;
	}

function unsetH2B_v3( hid )
	{
	//H2B_v3_timeout = setTimeout( 'setH2B_v3('+H2B_v3_Active+');', 2000 );
	}

function setH2B_v3_subline( hid )
	{
	$("#H2B_v3_I" + hid).css("position", "absolute");
	position = $("#H2B_v3_I" + hid).position();
	$("#H2B_subline").css("top", position.top + "px" );
	$("#H2B_v3_I" + hid).css("position", "static");
	}
	
function setH2B_v3_link( link )
	{
	$("#H2B_main").next().next().click( function() { window.location = link; } );
	}

function changeH2B_img( hid , changeType )
	{
	imgH2B = imgH2B_v3_pre[hid];
	
	if ( imgH2B.src != "" )
		{
		if ( changeType == 'fade')
			{
			imgH2B.id = 'H2B_main_new';
			$("#H2B_set").append( imgH2B );
			$("#H2B_main_new").css("position", "absolute").css("z-index", 2).css("width", "480px").css("height", "185px").css("display","none");
			$("#H2B_main_new").fadeIn("slow", function () {
				$("#H2B_main").remove();
				$("#H2B_main_new").attr("id", "H2B_main");
				if ( !$("#H2B_main") ) { $("#H2B_set").append( imgH2B ); }
				} );
			}
			else
			{
			$("#H2B_main").attr("src", imgH2B.src);
			}
		}
	}

function setH2B_v3_next()
	{
	if (H2B_v3_S)
		{
		nextA = H2B_v3_Active + 1;
		if ( H2B_v3_img[nextA] ) { H2B_v3_Active = nextA; } else { H2B_v3_Active = 0; }
		setH2B_v3( H2B_v3_Active , 'fade' );
		}
	setTimeout( 'setH2B_v3_next();', H2B_v3_changeTimer );
	}
