jQuery(document).ready(function(){
	$('#tesvideo').css({width: '640px', height: '428px'});
	$('#jquery-overlay').click(function(){closeDl()});
	$('#tesvideo #close').click(function(){closeDl()});
	$('#video').attr('href', 'javascript:void(0)');
	$('#video').click(function(){
			$('#jquery-overlay').css({
					display: 'block'
				}).animate({
					opacity: "0.6"
			}, 100,'', function(){
							//alert(swidth);
							$('#tesvideo').css({
								display: 'block'
							}).animate({
								opacity: "1"});
						}

			);
		});

	_update_container();
	$(window).resize(function() {
		_update_container();
	});
	$('ul.sf-menu').superfish({ delay: 250, animation: { opacity: 'show' }, speed: 155 });
	$('ul.tabs_buttons a').attr('href', 'javascript:void(0)');
	$('ul.tabs_buttons a').click(function() {
		// var index = jQuery('ul.tabs_buttons a').index(this);
		$('ul.tabs_buttons a').removeClass('active');
		$(this).addClass('active');
		$('ul.tabs_panels>li').hide();
		$('li#'+this.id+'_li').show();
		if($('#delete-this-div-atclick').length)
		{			$('#delete-this-div-atclick').remove();
			$('ul.items_list li span').css({				color: '#7D7D7D'			});		}
	});
	$('#month').mouseover(function(){
										$('#monthsel').addClass('over');
					}).mouseout(function(){
										$('#monthsel').removeClass('over');
					});
	$('#monthsel').mouseover(function(){
										$(this).addClass('over');
										$('#month').addClass('over');
					}).mouseout(function(){
										$(this).removeClass('over');
										$('#month').removeClass('over');
					});
	var $tabs = $('#tabs').tabs();

	var $tabs = $('#tabs').tabs();
	$(".ui-tabs-panel").each(function(i){
									  var totalSize = $(".ui-tabs-panel").size() - 1;
									  next = i + 2;
									  $(this).append("<a href='#' class='next-tab' id='fame_arrow_forw' rel='" + next + "'></a>");
									  prev = i;
									  $(this).append("<a href='#' class='prev-tab' id='fame_arrow_back' rel='" + prev + "'></a>");
	});

	$('.next-tab, .prev-tab').click(function() {
											 $tabs.tabs('select', $(this).attr("rel"));
											 return false;
	});
	var clicked = $('.main_gallery a:first');
	if(clicked.attr('rel') == 'gal')
	{
		galleryShow();
	}
	function galleryShow()
	{
		hide();
		return false;
	}
	function goImg()
	{
		var objImagePreloader = new Image();
		objImagePreloader.onload = function() {
			$('.main_gallery a').removeClass('active');
			clicked.addClass('active');
			if(clicked.prevAll("a").attr('rel') == 'gal'){	$('.photo_container #gallery_prev').show();}
			else{ $('.photo_container #gallery_prev').hide();}
			if(clicked.nextAll("a").attr('rel') == 'gal'){	$('.photo_container #gallery_next').show();}
			else{ $('.photo_container #gallery_next').hide();}
			resize(objImagePreloader.width,objImagePreloader.height+50);
			objImagePreloader.onload=function(){};
		}
		objImagePreloader.src = clicked.attr('href');
	}
	function show()
	{
		$('.photo_container img').attr('src', clicked.attr('href'));
		$('.photo_container img').fadeIn('slow');
		$('.photo_container #info').html("<strong>"+clicked.attr('title')+"</strong>"+clicked.children('img').attr('alt'));
	}
	function hide()
	{
		$('.photo_container img').fadeOut('slow', function(){  $('.photo_container #info').html("");goImg(); });
	}
	function resize(w,h)
	{
		$('#imgcontainer').animate({ width: w, height: h }, 500, function() { show(); });
	}
	$('.main_gallery a').bind('click',function(){
										clicked = $(this);
										galleryShow();
										return false;
	});
	$('.photo_container #gallery_prev').bind('click',function(){
												var btn = clicked.prev();
												//alert(clicked.prev().prev().html());
												if(btn.attr('rel') == 'gal')
												{
													clicked = btn;
													galleryShow();
												}
												else if(clicked.prev().prev().attr('rel') == 'gal')
												{
													clicked = clicked.prev().prev();
													galleryShow();
												}
												return false;
	});
	$('.photo_container #gallery_next').bind('click',function(){
												var btn = clicked.next();
												if(btn.attr('rel') == 'gal')
												{
													clicked = btn;
													galleryShow();
												}
												else if(clicked.next().next().attr('rel') == 'gal')
												{
													clicked = clicked.next().next();
													galleryShow();
												}
												return false;
	});
	$("#addMail").submit(function () {
			var bad=true;
			if(!jsfly.check_mail("addMailInp")  && bad){
				alert('E-mail is empty or wrong');
				var bad=false;
			}

			if(bad){
				var ssmail = $("#addMailInp").val();
				$.post("/index.php?request=1", { ssmail: ssmail },function(data){
     				if(data=='error1')
					{
						alert('It appears that you are already a subscriber of our mailing list');
					}
					if(data=='error2')
					{
						alert('E-mail is empty or wrong');
					}
					if(data=='ok')
					{
						alert('Thank you for subscribing');
					}
  				 });

			}
			return false;
	});
	$("#theForm").submit(function () {
			var bad=true;

			if(!jsfly.check("user_name")  && bad){
				$("#user_name").css({"border":"1px solid #cc0000"});
				$("em.user_name").css('display', 'block');
				var bad=false;
			} else
			{
				$("#user_name").css({"border":"1px solid #d2d2d2"});
				$("em.user_name").css('display', 'none');
			}

			if(!jsfly.check_mail("user_email")  && bad){
				$("#user_email").css({"border":"1px solid #cc0000"});
				$("em.user_email").css('display', 'block');
				var bad=false;
			} else
			{
				$("#user_email").css({"border":"1px solid #d2d2d2"});
				$("em.user_email").css('display', 'none');
			}

			if(!jsfly.check("captcha_word")  && bad){
				$("#captcha_word").css({"border":"1px solid #cc0000"});
				$("em.captcha_word").css('display', 'block');
				var bad=false;
			} else
			{
				$("#captcha_word").css({"border":"1px solid #d2d2d2"});
				$("em.captcha_word").css('display', 'none');
			}

			if(!jsfly.check("MESSAGE")  && bad){
				$("#MESSAGE").css({"border":"1px solid #cc0000"});
				$("em.MESSAGE").css('display', 'block');
				var bad=false;
			} else
			{
				$("#MESSAGE").css({"border":"1px solid #d2d2d2"});
				$("em.MESSAGE").css('display', 'none');
			}



			/*======================*/
			if(bad){
				return true;
			}
			else{
				return false;
			}

		}
	);
});
function closeDl()
{
	$('#tesvideo').fadeOut('fast',function(){});
	$('#jquery-overlay').fadeOut('fast',function(){});
}
function _update_container()
{
	var swidth = document.documentElement.clientWidth;
	var sheight = document.documentElement.clientHeight;
	var tesvideo = document.getElementById('tesvideo');
	if(!tesvideo) return;
	var style = tesvideo.currentStyle || getComputedStyle (tesvideo, '');
	var width = parseInt(style.width);
	var height = parseInt(style.height);
	var docHeight = document.documentElement.scrollHeight ? document.documentElement.scrollHeight : document.body.scrollHeight;
	var docWidth = document.documentElement.scrollWidth ? document.documentElement.scrollWidth : document.body.scrollWidth;
	$('#jquery-overlay').css({
		height: docHeight,
		width: docWidth
	});
	$('#tesvideo').css({
		top: (sheight - height)/2,
		left: (swidth - width)/2
	});
}
var jsfly={
	check_mail:function(idd){
		var val=$("#"+idd).val();
		var dd= jsfly.mailc.test(val);
		/*alert(dd);*/
		return dd;
	},
	check:function(idd){
		var val=$("#"+idd).val();
		return jsfly.any.test(val);
	},
	check_num:function(idd){

		var val=$("#"+idd).val();
		return jsfly.nnsss.test(val);
	},

	mailc:/^[a-z0-9]{1}[a-z0-9\-_\.]+@[\.a-z0-9\-_]+\.[a-z]{2,4}$/i,

	any:/.+/i,
	nnsss:/^[0-9]+$/i
};
