/* Preload Image */
var image1 = new Image(); image1.src = "/images/new2wind/portfolio_big_window_bg.png";
var image2 = new Image(); image2.src = "/images/new2wind/portfolio_window_bg.png";
var image3 = new Image(); image3.src = "/images/new2wind/portfolio_window_bg_right.png";
var image4 = new Image(); image4.src = "/images/new2wind/icons_menu_1_hover.png";
var image5 = new Image(); image5.src = "/images/new2wind/icons_menu_2_hover.png";
var image6 = new Image(); image6.src = "/images/new2wind/icons_menu_3_hover.png";
var image7 = new Image(); image7.src = "/images/new2wind/body_bg.gif";

/* Checkbox */
$('.niceCheck').each(function() {
	/* при загрузке страницы нужно проверить какое значение имеет чекбокс и в соответствии с ним выставить вид */
	changeCheckStart($(this));
});

function changeCheck(el) {
	/* функция смены вида и значения чекбокса, el - span контейнер для обычного чекбокса, input - чекбокс */
	var el = el,
	input = el.find("input").eq(0);
	if(!input.attr("checked")) {
		el.css("background-position","0 -20px");	
		input.attr("checked", true)
	} else {
		el.css("background-position","0 0");	
		input.attr("checked", false)
	}
	return true;
}

function changeCheckStart(el) {
	/*  если установлен атрибут checked, меняем вид чекбокса */
	var el = el,
	input = el.find("input").eq(0);
	if(input.attr("checked")) {
		el.css("background-position","0 -20px");
	}
	return true;
}

function ReNewCaptchaById(imageId, captchaKey, captchaHeight) {	
	// Пытаемся получить скрытый объект для input-а
	var captchaObject = document.getElementById(imageId);

	// Элемента нет, добавим его
	if (null != captchaObject && undefined !== captchaObject)
	{
		var antiCache = Math.floor(Math.random()*100000);
		captchaObject.src = "/captcha.php?get_captcha=" + captchaKey + "&height=" + captchaHeight + "&anc=" + antiCache;
	}
}

$(document).ready(function() {
	$("a.zoomimage").fancybox({
		'hideOnOverlayClick': true,
		'hideOnContentClick': true,
		'enableEscapeButton': true,
		'overlayShow'	: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'speedIn': '1000',
		'speedOut': '1000'
	});

	/* Dictionary */
	$('.hintable').click(function() {
		$('.hint:visible').slideUp('normal');
		$(this).next('.hint').slideDown('normal');
		return false;
	});

	/* Opinions */
	$('.close').click(function(){
		$('.hint:visible').hide('normal');
		$('.opinion_popup').hide('normal');
		$('.portfolio_popup').hide('normal');
		$('#orderfield').hide('normal');
		$('#orderfield_bg').hide();
		$('#orderfield_send').hide();
	});

	$('#orderfield_bg').click(function() {
		$('#orderfield_bg').hide();
		$('#orderfield_send').hide();
	});

	$('.opinion_popup').click(function(){
		$('.opinion_popup').hide('normal');
	});

	$('.portfolio_popup').click(function(){
		$('.portfolio_popup').hide('normal');
	});

	$(".portfolio_item").click(function() {
		$('#orderfield').hide('normal');
		$('.portfolio_popup:visible').hide('normal');
		$('.opinion_popup:visible').hide('normal');
		$(this).next().show('normal');
		return false;
	});

	$(".opinion_item").click(function() {
		$('#orderfield').hide('normal');
		$('.portfolio_popup:visible').hide('normal');
		$('.opinion_popup:visible').hide('normal');
		$(this).next('.opinion_popup').show('normal');
		return false;
	});

	$(".valuation1").click(function() {
		$('.portfolio_popup:visible').hide('normal');
		$('.opinion_popup:visible').hide('normal');
		$('#orderfield').css('top', 540);
		$('#orderfield').show('normal');
		return false;
	});

	$(".valuation2").click(function() {
		$('.portfolio_popup:visible').hide('normal');
		$('.opinion_popup:visible').hide('normal');
		$('#orderfield').css('top', 1300);
		$('#orderfield').show('normal');
		return false;
	});

	$('.name').click(function() {
		$('#orderfield').hide('normal');
		$('.portfolio_popup:visible').hide('normal');
		$('.opinion_popup:visible').hide('normal');
		$('#show'+$(this).attr('id') ).show('normal');
	}); 

	$('.gototop').click(function(){
		$('html, body').animate({
			scrollTop: '0px', 
		}, 'slow');
	});

	$('h2.big').click(function() {
		$(this).next('.block_in').toggle(400);
	});

	$('h2.big').hover(function() {
		$(this).css('text-decoration', 'none');
	},
	function() {
		$(this).css('text-decoration', 'underline');
	});

	$('#mycarousel').jcarousel({ });
});
