$(document).ready(function() {
	
	cssfix();
	
	_seanc = $(".seanses tr:has(td)");
	seanc();
	
	shopsButSel = $("#shops .buttons .one");
	shopsButASel = $("#shops .buttons .one, #shops .buttons .one a");
	brands1 = $("#brands");
	uli = $("#ul");
	sel1 = 0;
	shopsbutton();
	
	brandsOne = $("#brands .one");
	brands2();
	
	loginLinkSel = $("#login .enter, #login .register");
	loginSel = $("#login");
	loginTextLink = $("#html .textlink");
	login();
	closeSel = $("#login .close");
	closeLogin();
	
	icnSel = $("#icns a");
	icns();
	
	searchinput = $("#search .lfield input");
	searchfield();
	searchload();
	
	myVoteSel = $("#votes .my");
	myVote = $("#myvote");
	votes();
	
	nArhivOne = $("#nArhiv .yOne");
	nArhivMonth = $("#nArhiv .month");
	newArhive();

	comment_del();
	
	_galOne = $("#gallery .goHint");
	galHint();

	$("#loginshow").click(function () {
		if($("#hiddiv").css("display")=='none') $("#hiddiv").show();
		else $("#hiddiv").hide();
	});
	
	_mainInner = $("#mainInner");
	_idbody = $("#body");
	columnSizeble();
	
});

function columnSizeble() {
	sizeble1 = function () {
		_awidth1 = _idbody.width();
		if (_awidth1 >= 1230) {
			_mainInner.removeClass("lc");
			_mainInner.addClass("lcr");
		} else {
			_mainInner.removeClass("lcr");
			_mainInner.addClass("lc");
		}
	}
	var atime1;
	timesizeble1 = function () {
		clearTimeout(atime1);
		atime1 = setTimeout(sizeble1, 200);
	}
	if (_mainInner.hasClass("sizeble")) {
		$(window).resize(timesizeble1).load(timesizeble1);
	}
}

function seanc () {
	_seanc.mouseenter(function () {
		$(this).addClass("hover");
	}).mouseleave(function () {
		$(this).removeClass("hover");
	});
}

function galHint() {
	_galOne.mouseenter(function () {
		element = $(this).find(".galHint");
		$(body).prepend('<div id="galHint">' + element.html() + '</div>');
		_ael = $("#galHint");
		$(document).mousemove(function (e) {
			l = e.pageX + 25;
			t = e.pageY - 10;
			_ael.css({top: t, left: l});
		});
	}).mouseleave(function () {
		$("#galHint").remove();
	});
}

function newArhive() {
	nArhivOne.click(function () {
		nArhivOne.removeClass("sel");
		nArhivMonth.removeClass("sell");
		//id = $(this).attr("id");
		$(this).addClass("sel");
		$("#arh" + $(this).attr("id")).addClass("sell");
		
		if ($(this).attr("id") != "M0") return false;
	});
}

function cssfix() {
}

function brands2() {
	brandsOne.mouseenter(function () {
		brandsOne.css("z-index", "100");
		$(this).css("z-index", "101");
		$(this).find(".border").show().animate({left:"-45px", top:"-45px", height:"213px", width:"213px"}, 150);
		$(this).find(".big").animate({height:"175px", width:"175px"}, 150);
	}).mouseleave(function () {
		$(this).find(".border").animate({left:"-15px", top:"-15px", height:"153px", width:"153px"}, 150).queue(function () {$(this).hide();$(this).dequeue();});
		$(this).find(".big").animate({height:"115px", width:"115px"}, 150);
	});
}

function shopsbutton() {
	shopsButSel.mouseenter(function () {
		sel1 = $(this);
		if (!$(this).hasClass("sel")) {
			$(this).addClass("hover");
		}
	}).mouseleave(function () {
		if (!$(this).hasClass("sel")) {
			$(this).removeClass("hover");
		}
	});
	shopsButASel.click(function () {
		shopstoggle();
		return false;
	});
}

function shopstoggle() {
	shopsButSel.removeClass("sel").removeClass("hover");
	sel1.addClass("sel");
	if (brands1.css("display") == "block") {
		brands1.animate({height: "hide"}, 200, function () {
			uli.animate({height: "show"}, 150);
		});
	} else {
		uli.animate({height: "hide"}, 200, function () {
			brands1.animate({height: "show"}, 150);
		});
	}
}

function votes() {
	myVoteSel.click(function () {
		myVote.toggle();
		myVote.find("input").focus();
	});
	myVote.find(".ok").click(function () {
		a = myVote.find("input").attr("value");
		if (a) myVoteSel.text("Свой вариант: " + a); else myVoteSel.text("Свой вариант");
		myVote.toggle();
	});
}

function searchfield() {
	if (!searchinput.attr("value")) { searchinput.attr("value", "Поиск по сайту").addClass("no"); }
	$(document).unbind("click", searchfield);
	searchinput.unbind("mouseenter").unbind("mouseleave");
}

function searchload() {
	$("#searchex").click(function () { $("#search input").attr("value", $("#searchex").text()).removeClass("no"); return false;});

	searchinput.click(function () { 
		if ($(this).hasClass("no")) {
			$(this).attr("value", "").removeClass("no");
		}
		$(this).mouseenter(function () { $(document).unbind("click", searchfield); }).mouseleave(function () { $(document).click(searchfield); });
	});
}


function closeLogin()  {
	closeSel.mouseover(function () {
		$(this).addClass("hover");
	}).mouseout(function () {
		$(this).removeClass("hover");
	});
	closeSel.find(".click").click(function () {
				loginSel.find("#register").hide();
				loginSel.find("#enter").hide();
	});
}

function login() {
	loginLinkSel.click(function () {
		switch ($(this).attr("class")) {
			case "enter": {
				loginSel.find("#register").hide();
				loginSel.find("#enter").show();
			} break;
			case "register": {
				loginSel.find("#enter").hide();
				loginSel.find("#register").show();
			} break;
		}
	});
	
	loginTextLink.click(function () {
		loginSel.find("#register").hide();
		loginSel.find("#enter").show();
	});
}

function icns() {
	icnSel.mouseover(function () {
		$(this).addClass("hover");
	}).mouseout(function () {
		$(this).removeClass("hover");
	});
}

/* Main News

function mainNew() {
	mnb.mouseover(function () {
		$(this).addClass("hover");
	}).mouseout(function () {
		$(this).removeClass("hover");
	});
	mnb.mousedown(function () {
		if (!$(this).hasClass("push")) {
			mnb.removeClass("push");
			$(this).addClass("push");
			new_mnbSelect = $(this).attr("id");
			if ($.browser.msie && (jQuery.browser.version != "6.0")) {
				$("#mnBox" + mnbSelect).css("display", "none");
				$("#mnBox" + new_mnbSelect).css("display", "block");
			} else {
				$("#mnBox" + mnbSelect).animate({"opacity" : 0}, 200).queue(function () {
					$("#mnBox").height($("#mnBox").innerHeight());
					$(this).css("display", "none");
					$("#mnBox" + new_mnbSelect).animate({"opacity" : 0}, 0).css("display", "block").animate({"opacity" : 1}, 150);
					$("#mnBox").animate({"height" : $("#mnBox" + new_mnbSelect).innerHeight()}, 150).queue(function () {$(this).css({"height" : "auto"}); $(this).dequeue();});
					$(this).dequeue();
				});
			}
				
			mnbSelect = new_mnbSelect;
		}
	});
}

Main News ¡V */

function comment_del() {
	$(".removeMessage").click(function () {
		var answer = confirm("Вы уверены что хотите удалить комментарий?");
		if (answer) document.forms['f'+$(this).attr("val")].submit();
		return false;
	});
}

function checkAll(id) {

if(id=='ent') { //вход
	if (chF('ent_pass') && chM('ent_mail')) $("#ent_send").removeAttr("disabled");
	else $("#ent_send").attr("disabled", true);
} else if(id=='reg') { //регистрация
	if (chF('reg_name') && chF('cpass') && chF('cpass2') && chM('reg_mail')) $("#reg_send").removeAttr("disabled");
	else $("#reg_send").attr("disabled", true);
} else if(id=='p'){ //профиль
	if(star_chF('pname')) $("#p_edit").removeAttr("disabled");
	else $("#p_edit").attr("disabled", true);
} else if(id=='re'){ //смена пароля
	if(chM('rmail')) $("#r_send").removeAttr("disabled");
	else $("#r_send").attr("disabled", true);
} else if(id=='faq'){ //вопрос-ответ
	star_chM('faq_mail');
	if(star_chM('faq_mail') && star_chF('faq_text')) $("#faq_send").removeAttr("disabled");
	else $("#faq_send").attr("disabled", true);
} else if(id=='af'){ //афиша комментарий
	if(star_chF('af_text')) $("#af_send").removeAttr("disabled");
	else $("#af_send").attr("disabled", true);
} else if(id=='rent'){ //заявка на аренду
	star_chF('rent_tel');star_chF('rent_scope');star_chF('rent_gr');
	if(star_chF('rent_tel')&&star_chF('rent_scope')&&star_chF('rent_gr')) $("#rent_send").removeAttr("disabled");
	else $("#rent_send").attr("disabled", true);
} else if(id=='comp'){ //заявка на аренду
	star_chF('jname'); star_chM('jmail'); star_chF('jtel'); star_chF('jcaption'); star_chF('jtext');
	if (star_chF('jname')&&star_chM('jmail')&&star_chF('jtel')&&star_chF('jcaption')&&star_chF('jtext')) $("#jsend").removeAttr("disabled");
	else $("#jsend").attr("disabled", true);
} else { //feedback
	star_chM('cmail');
	if (star_chF('cname') && star_chF('ctel') && star_chF('ctext') && star_chM('cmail')) document.getElementById('csend').disabled = false; 
	else document.getElementById('csend').disabled = true;
}
}

function chF(id) {
	var val = document.getElementById(id).value;
	val = removeSpaces(val);
	if((!val) || (val=="nonesel")) return false;
	else return true;
}

function chM(id) {
	var value = document.getElementById(id).value;
	var oRegExp = /^[A-Za-z0-9][-\w]*(\.[A-Za-z0-9][-\w]*)*@[A-Za-z0-9][-\w]*(\.[A-Za-z0-9][-\w]*)*\.[a-zA-Z]{2,4}$/
	value = value.replace( new RegExp('/\(.*?\)/'), '' );
	if(oRegExp.test(value)) return true; else return false;
}

function star_chF(id) {
	var thisElement = document.getElementById(id);
	var tdElement = document.getElementById('star_' + id);
	var sValue = thisElement.value;
	sValue = removeSpaces(sValue);

	if ((sValue == "") || (sValue == "nonesel")) { tdElement.innerHTML = "*"; return false; }
	else { tdElement.innerHTML = ""; return true; }
}
function star_chM(id) {
	var value = document.getElementById(id).value;
	var oRegExp = /^[A-Za-z0-9][-\w]*(\.[A-Za-z0-9][-\w]*)*@[A-Za-z0-9][-\w]*(\.[A-Za-z0-9][-\w]*)*\.[a-zA-Z]{2,4}$/
	value = value.replace( new RegExp('/\(.*?\)/'), '' );
	if (oRegExp.test(value)) { $("#star_"+id).text(""); return true; } 
	else { $("#star_"+id).text("*"); return false; }
}

function changePass() {
var pass1 = document.getElementById("pass1").value; pass1 = removeSpaces(pass1);
var pass2 = document.getElementById("pass2").value; pass2 = removeSpaces(pass2);
var pass3 = document.getElementById("oldpass").value; pass3 = removeSpaces(pass3);

	if((pass1=="") || (pass2=="") || (pass3=="")) {
		$("#ch_pass").attr("disabled", true);
		//$("chpass_error").css("display", "none");
		//$("#chpass_error").text("Заполните все поля");
		if(pass1=="") $("#star_pass1").text("*"); else $("#star_pass1").text("");
		if(pass2=="")$("#star_pass2").text("*"); else $("#star_pass2").text("");
		if(pass3=="")$("#star_oldpass").text("*"); else $("#star_oldpass").text("");
	} else if(pass1==pass2) {
			$("#ch_pass").removeAttr("disabled");
			//$("chpass_error").css("display", "none");
			//$("#chpass_error").text("");
			$("#star_pass1").text("");
			$("#star_pass2").text("");
			$("#star_oldpass").text("");
		} else {
			$("#ch_pass").attr("disabled", true);
			//$("chpass_error").css("display", "block");
			//$("#chpass_error").text("Пароли не совпадают!");
			$("#star_pass1").text("*");
			$("#star_pass2").text("*");
			//$("#star_oldpass").text("*");
	}
}
/*УДАЛИТЬ ВСЕ ПРОБЕЛЫ*/
var allSpacesRe = /\s+/g;
function removeSpaces(s) { return s.replace(allSpacesRe, ""); }

