/*!
 * FancyBox - jQuery Plugin
 * Simple and fancy lightbox alternative
 *
 * Examples and documentation at: http://fancybox.net
 * 
 * Copyright (c) 2008 - 2010 Janis Skarnelis
 * That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
 * 
 * Version: 1.3.2 (20/10/2010)
 * Requires: jQuery v1.3+
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
(function(a){var m,t,u,f,D,h,E,n,z,A,q=0,e={},o=[],p=0,c={},l=[],I=null,v=new Image,J=/\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,W=/[^\.]\.(swf)\s*$/i,K,L=1,y=0,s="",r,j,i=false,B=a.extend(a("<div/>")[0],{prop:0}),M=a.browser.msie&&a.browser.version<7&&!window.XMLHttpRequest,N=function(){t.hide();v.onerror=v.onload=null;I&&I.abort();m.empty()},O=function(){if(false===e.onError(o,q,e)){t.hide();i=false}else{e.titleShow=false;e.width="auto";e.height="auto";m.html('<p id="fancybox-error">The requested content cannot be loaded.<br />Please try again later.</p>'); F()}},H=function(){var b=o[q],d,g,k,C,P,w;N();e=a.extend({},a.fn.fancybox.defaults,typeof a(b).data("fancybox")=="undefined"?e:a(b).data("fancybox"));w=e.onStart(o,q,e);if(w===false)i=false;else{if(typeof w=="object")e=a.extend(e,w);k=e.title||(b.nodeName?a(b).attr("title"):b.title)||"";if(b.nodeName&&!e.orig)e.orig=a(b).children("img:first").length?a(b).children("img:first"):a(b);if(k===""&&e.orig&&e.titleFromAlt)k=e.orig.attr("alt");d=e.href||(b.nodeName?a(b).attr("href"):b.href)||null;if(/^(?:javascript)/i.test(d)|| d=="#")d=null;if(e.type){g=e.type;if(!d)d=e.content}else if(e.content)g="html";else if(d)g=d.match(J)?"image":d.match(W)?"swf":a(b).hasClass("iframe")?"iframe":d.indexOf("#")===0?"inline":"ajax";if(g){if(g=="inline"){b=d.substr(d.indexOf("#"));g=a(b).length>0?"inline":"ajax"}e.type=g;e.href=d;e.title=k;if(e.autoDimensions&&e.type!=="iframe"&&e.type!=="swf"){e.width="auto";e.height="auto"}if(e.modal){e.overlayShow=true;e.hideOnOverlayClick=false;e.hideOnContentClick=false;e.enableEscapeButton=false; e.showCloseButton=false}e.padding=parseInt(e.padding,10);e.margin=parseInt(e.margin,10);m.css("padding",e.padding+e.margin);a(".fancybox-inline-tmp").unbind("fancybox-cancel").bind("fancybox-change",function(){a(this).replaceWith(h.children())});switch(g){case "html":m.html(e.content);F();break;case "inline":if(a(b).parent().is("#fancybox-content")===true){i=false;break}a('<div class="fancybox-inline-tmp" />').hide().insertBefore(a(b)).bind("fancybox-cleanup",function(){a(this).replaceWith(h.children())}).bind("fancybox-cancel", function(){a(this).replaceWith(m.children())});a(b).appendTo(m);F();break;case "image":i=false;a.fancybox.showActivity();v=new Image;v.onerror=function(){O()};v.onload=function(){i=true;v.onerror=v.onload=null;e.width=v.width;e.height=v.height;a("<img />").attr({id:"fancybox-img",src:v.src,alt:e.title}).appendTo(m);Q()};v.src=d;break;case "swf":C='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+e.width+'" height="'+e.height+'"><param name="movie" value="'+d+'"></param>';P=""; a.each(e.swf,function(x,G){C+='<param name="'+x+'" value="'+G+'"></param>';P+=" "+x+'="'+G+'"'});C+='<embed src="'+d+'" type="application/x-shockwave-flash" width="'+e.width+'" height="'+e.height+'"'+P+"></embed></object>";m.html(C);F();break;case "ajax":i=false;a.fancybox.showActivity();e.ajax.win=e.ajax.success;I=a.ajax(a.extend({},e.ajax,{url:d,data:e.ajax.data||{},error:function(x){x.status>0&&O()},success:function(x,G,U){if(U.status==200){if(typeof e.ajax.win=="function"){w=e.ajax.win(d,x,G, U);if(w===false){t.hide();return}else if(typeof w=="string"||typeof w=="object")x=w}m.html(x);F()}}}));break;case "iframe":Q()}}else O()}},F=function(){m.width(e.width);m.height(e.height);if(e.width=="auto")e.width=m.width();if(e.height=="auto")e.height=m.height();Q()},Q=function(){var b,d;t.hide();if(f.is(":visible")&&false===c.onCleanup(l,p,c)){a.event.trigger("fancybox-cancel");i=false}else{i=true;a(h.add(u)).unbind();a(window).unbind("resize.fb scroll.fb");a(document).unbind("keydown.fb");f.is(":visible")&& c.titlePosition!=="outside"&&f.css("height",f.height());l=o;p=q;c=e;if(c.overlayShow){u.css({"background-color":c.overlayColor,opacity:c.overlayOpacity,cursor:c.hideOnOverlayClick?"pointer":"auto",height:a(document).height()});if(!u.is(":visible")){M&&a("select:not(#fancybox-tmp select)").filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one("fancybox-cleanup",function(){this.style.visibility="inherit"});u.show()}}else u.hide();h.get(0).scrollTop=0;h.get(0).scrollLeft= 0;j=X();s=c.title||"";y=0;n.empty().removeAttr("style").removeClass();if(c.titleShow!==false){if(a.isFunction(c.titleFormat))b=c.titleFormat(s,l,p,c);else b=s&&s.length?c.titlePosition=="float"?'<table id="fancybox-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fancybox-title-float-left"></td><td id="fancybox-title-float-main">'+s+'</td><td id="fancybox-title-float-right"></td></tr></table>':'<div id="fancybox-title-'+c.titlePosition+'">'+s+"</div>":false;s=b;if(!(!s||s==="")){n.addClass("fancybox-title-"+ c.titlePosition).html(s).appendTo("body").show();switch(c.titlePosition){case "inside":n.css({width:j.width-c.padding*2,marginLeft:c.padding,marginRight:c.padding});y=n.outerHeight(true);n.appendTo(D);j.height+=y;break;case "over":n.css({marginLeft:c.padding,width:j.width-c.padding*2,bottom:c.padding}).appendTo(D);break;case "float":n.css("left",parseInt((n.width()-j.width-40)/2,10)*-1).appendTo(f);break;default:n.css({width:j.width-c.padding*2,paddingLeft:c.padding,paddingRight:c.padding}).appendTo(f)}}}n.hide(); if(f.is(":visible")){a(E.add(z).add(A)).hide();b=f.position();r={top:b.top,left:b.left,width:f.width(),height:f.height()};d=r.width==j.width&&r.height==j.height;h.fadeTo(c.changeFade,0.3,function(){var g=function(){h.html(m.contents()).fadeTo(c.changeFade,1,R)};a.event.trigger("fancybox-change");h.empty().removeAttr("filter").css({"border-width":c.padding,width:j.width-c.padding*2,height:c.type=="image"||c.type=="swf"||c.type=="iframe"?j.height-y-c.padding*2:"auto"});if(d)g();else{B.prop=0;a(B).animate({prop:1}, {duration:c.changeSpeed,easing:c.easingChange,step:S,complete:g})}})}else{f.removeAttr("style");h.css("border-width",c.padding);if(c.transitionIn=="elastic"){r=V();h.html(m.contents());f.show();if(c.opacity)j.opacity=0;B.prop=0;a(B).animate({prop:1},{duration:c.speedIn,easing:c.easingIn,step:S,complete:R})}else{c.titlePosition=="inside"&&y>0&&n.show();h.css({width:j.width-c.padding*2,height:c.type=="image"||c.type=="swf"||c.type=="iframe"?j.height-y-c.padding*2:"auto"}).html(m.contents());f.css(j).fadeIn(c.transitionIn== "none"?0:c.fadeIn,R)}}}},Y=function(){if(c.enableEscapeButton||c.enableKeyboardNav)a(document).bind("keydown.fb",function(b){if(b.keyCode==27&&c.enableEscapeButton){b.preventDefault();a.fancybox.close()}else if((b.keyCode==37||b.keyCode==39)&&c.enableKeyboardNav&&b.target.tagName!=="INPUT"&&b.target.tagName!=="TEXTAREA"&&b.target.tagName!=="SELECT"){b.preventDefault();a.fancybox[b.keyCode==37?"prev":"next"]()}});if(c.showNavArrows){if(c.cyclic&&l.length>1||p!==0)z.show();if(c.cyclic&&l.length>1|| p!=l.length-1)A.show()}else{z.hide();A.hide()}},R=function(){if(!a.support.opacity){h.get(0).style.removeAttribute("filter");f.get(0).style.removeAttribute("filter")}f.css("height","auto");c.type!=="image"&&c.type!=="swf"&&c.type!=="iframe"&&h.css("height","auto");s&&s.length&&n.show();c.showCloseButton&&E.show();Y();c.hideOnContentClick&&h.bind("click",a.fancybox.close);c.hideOnOverlayClick&&u.bind("click",a.fancybox.close);a(window).bind("resize.fb",a.fancybox.resize);c.centerOnScroll&&a(window).bind("scroll.fb", a.fancybox.center);if(c.type=="iframe")a('<iframe id="fancybox-frame" name="fancybox-frame'+(new Date).getTime()+'" frameborder="0" hspace="0" '+(a.browser.msie?'allowtransparency="true""':"")+' scrolling="'+e.scrolling+'" src="'+c.href+'"></iframe>').appendTo(h);f.show();i=false;a.fancybox.center();c.onComplete(l,p,c);var b,d;if(l.length-1>p){b=l[p+1].href;if(typeof b!=="undefined"&&b.match(J)){d=new Image;d.src=b}}if(p>0){b=l[p-1].href;if(typeof b!=="undefined"&&b.match(J)){d=new Image;d.src=b}}}, S=function(b){var d={width:parseInt(r.width+(j.width-r.width)*b,10),height:parseInt(r.height+(j.height-r.height)*b,10),top:parseInt(r.top+(j.top-r.top)*b,10),left:parseInt(r.left+(j.left-r.left)*b,10)};if(typeof j.opacity!=="undefined")d.opacity=b<0.5?0.5:b;f.css(d);h.css({width:d.width-c.padding*2,height:d.height-y*b-c.padding*2})},T=function(){return[a(window).width()-c.margin*2,a(window).height()-c.margin*2,a(document).scrollLeft()+c.margin,a(document).scrollTop()+c.margin]},X=function(){var b= T(),d={},g=c.autoScale,k=c.padding*2;d.width=c.width.toString().indexOf("%")>-1?parseInt(b[0]*parseFloat(c.width)/100,10):c.width+k;d.height=c.height.toString().indexOf("%")>-1?parseInt(b[1]*parseFloat(c.height)/100,10):c.height+k;if(g&&(d.width>b[0]||d.height>b[1]))if(e.type=="image"||e.type=="swf"){g=c.width/c.height;if(d.width>b[0]){d.width=b[0];d.height=parseInt((d.width-k)/g+k,10)}if(d.height>b[1]){d.height=b[1];d.width=parseInt((d.height-k)*g+k,10)}}else{d.width=Math.min(d.width,b[0]);d.height= Math.min(d.height,b[1])}d.top=parseInt(Math.max(b[3]-20,b[3]+(b[1]-d.height-40)*0.5),10);d.left=parseInt(Math.max(b[2]-20,b[2]+(b[0]-d.width-40)*0.5),10);return d},V=function(){var b=e.orig?a(e.orig):false,d={};if(b&&b.length){d=b.offset();d.top+=parseInt(b.css("paddingTop"),10)||0;d.left+=parseInt(b.css("paddingLeft"),10)||0;d.top+=parseInt(b.css("border-top-width"),10)||0;d.left+=parseInt(b.css("border-left-width"),10)||0;d.width=b.width();d.height=b.height();d={width:d.width+c.padding*2,height:d.height+ c.padding*2,top:d.top-c.padding-20,left:d.left-c.padding-20}}else{b=T();d={width:c.padding*2,height:c.padding*2,top:parseInt(b[3]+b[1]*0.5,10),left:parseInt(b[2]+b[0]*0.5,10)}}return d},Z=function(){if(t.is(":visible")){a("div",t).css("top",L*-40+"px");L=(L+1)%12}else clearInterval(K)};a.fn.fancybox=function(b){if(!a(this).length)return this;a(this).data("fancybox",a.extend({},b,a.metadata?a(this).metadata():{})).unbind("click.fb").bind("click.fb",function(d){d.preventDefault();if(!i){i=true;a(this).blur(); o=[];q=0;d=a(this).attr("rel")||"";if(!d||d==""||d==="nofollow")o.push(this);else{o=a("a[rel="+d+"], area[rel="+d+"]");q=o.index(this)}H()}});return this};a.fancybox=function(b,d){var g;if(!i){i=true;g=typeof d!=="undefined"?d:{};o=[];q=parseInt(g.index,10)||0;if(a.isArray(b)){for(var k=0,C=b.length;k<C;k++)if(typeof b[k]=="object")a(b[k]).data("fancybox",a.extend({},g,b[k]));else b[k]=a({}).data("fancybox",a.extend({content:b[k]},g));o=jQuery.merge(o,b)}else{if(typeof b=="object")a(b).data("fancybox", a.extend({},g,b));else b=a({}).data("fancybox",a.extend({content:b},g));o.push(b)}if(q>o.length||q<0)q=0;H()}};a.fancybox.showActivity=function(){clearInterval(K);t.show();K=setInterval(Z,66)};a.fancybox.hideActivity=function(){t.hide()};a.fancybox.next=function(){return a.fancybox.pos(p+1)};a.fancybox.prev=function(){return a.fancybox.pos(p-1)};a.fancybox.pos=function(b){if(!i){b=parseInt(b);o=l;if(b>-1&&b<l.length){q=b;H()}else if(c.cyclic&&l.length>1){q=b>=l.length?0:l.length-1;H()}}};a.fancybox.cancel= function(){if(!i){i=true;a.event.trigger("fancybox-cancel");N();e.onCancel(o,q,e);i=false}};a.fancybox.close=function(){function b(){u.fadeOut("fast");n.empty().hide();f.hide();a.event.trigger("fancybox-cleanup");h.empty();c.onClosed(l,p,c);l=e=[];p=q=0;c=e={};i=false}if(!(i||f.is(":hidden"))){i=true;if(c&&false===c.onCleanup(l,p,c))i=false;else{N();a(E.add(z).add(A)).hide();a(h.add(u)).unbind();a(window).unbind("resize.fb scroll.fb");a(document).unbind("keydown.fb");h.find("iframe").attr("src",M&& /^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank");c.titlePosition!=="inside"&&n.empty();f.stop();if(c.transitionOut=="elastic"){r=V();var d=f.position();j={top:d.top,left:d.left,width:f.width(),height:f.height()};if(c.opacity)j.opacity=1;n.empty().hide();B.prop=1;a(B).animate({prop:0},{duration:c.speedOut,easing:c.easingOut,step:S,complete:b})}else f.fadeOut(c.transitionOut=="none"?0:c.speedOut,b)}}};a.fancybox.resize=function(){u.is(":visible")&&u.css("height",a(document).height()); a.fancybox.center(true)};a.fancybox.center=function(b){var d,g;if(!i){g=b===true?1:0;d=T();!g&&(f.width()>d[0]||f.height()>d[1])||f.stop().animate({top:parseInt(Math.max(d[3]-20,d[3]+(d[1]-h.height()-40)*0.5-c.padding)),left:parseInt(Math.max(d[2]-20,d[2]+(d[0]-h.width()-40)*0.5-c.padding))},typeof b=="number"?b:200)}};a.fancybox.init=function(){if(!a("#fancybox-wrap").length){a("body").append(m=a('<div id="fancybox-tmp"></div>'),t=a('<div id="fancybox-loading"><div></div></div>'),u=a('<div id="fancybox-overlay"></div>'), f=a('<div id="fancybox-wrap"></div>'));D=a('<div id="fancybox-outer"></div>').append('<div class="fancybox-bg" id="fancybox-bg-n"></div><div class="fancybox-bg" id="fancybox-bg-ne"></div><div class="fancybox-bg" id="fancybox-bg-e"></div><div class="fancybox-bg" id="fancybox-bg-se"></div><div class="fancybox-bg" id="fancybox-bg-s"></div><div class="fancybox-bg" id="fancybox-bg-sw"></div><div class="fancybox-bg" id="fancybox-bg-w"></div><div class="fancybox-bg" id="fancybox-bg-nw"></div>').appendTo(f); D.append(h=a('<div id="fancybox-content"></div>'),E=a('<a id="fancybox-close"></a>'),n=a('<div id="fancybox-title"></div>'),z=a('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),A=a('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>'));E.click(a.fancybox.close);t.click(a.fancybox.cancel);z.click(function(b){b.preventDefault();a.fancybox.prev()});A.click(function(b){b.preventDefault();a.fancybox.next()}); a.fn.mousewheel&&f.bind("mousewheel.fb",function(b,d){b.preventDefault();a.fancybox[d>0?"prev":"next"]()});a.support.opacity||f.addClass("fancybox-ie");if(M){t.addClass("fancybox-ie6");f.addClass("fancybox-ie6");a('<iframe id="fancybox-hide-sel-frame" src="'+(/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank")+'" scrolling="no" border="0" frameborder="0" tabindex="-1"></iframe>').prependTo(D)}}};a.fn.fancybox.defaults={padding:10,margin:40,opacity:false,modal:false,cyclic:false, scrolling:"auto",width:560,height:340,autoScale:true,autoDimensions:true,centerOnScroll:false,ajax:{},swf:{wmode:"transparent"},hideOnOverlayClick:true,hideOnContentClick:false,overlayShow:true,overlayOpacity:0.7,overlayColor:"#777",titleShow:true,titlePosition:"float",titleFormat:null,titleFromAlt:false,transitionIn:"fade",transitionOut:"fade",speedIn:300,speedOut:300,changeSpeed:300,changeFade:"fast",easingIn:"swing",easingOut:"swing",showCloseButton:true,showNavArrows:true,enableEscapeButton:true, enableKeyboardNav:true,onStart:function(){},onCancel:function(){},onComplete:function(){},onCleanup:function(){},onClosed:function(){},onError:function(){}};a(document).ready(function(){a.fancybox.init()})})(jQuery);



/* Document Load */
jQuery(document).ready(function() {
	
	if (jQuery('#GalleryCarousel').size() > 0)
		jQuery('#GalleryCarousel').jcarousel({
			wrap: 'circular',
			scroll: 1,        
			buttonNextHTML: null,
			buttonPrevHTML: null,
			itemVisibleInCallback:  {onBeforeAnimation: Gallery.CarouselItemVisibleInCallback},
			itemVisibleOutCallback: {onAfterAnimation: Gallery.CarouselVisibleOutCallback},
			initCallback:           Gallery.CarouselInitCallback
		});
	
	
    Gallery.Init();
	Menu.Init();
	Projects.Init();
	News.Init();
	Faq.Init();
	Orders.Init();
	setButtons();
	setOpacity();
    
    Objects.render();
    fancy.render();
    
    jQuery('.flash-wrapper').mousewheel(function(event){
       
    
    return false;});
    
});

/**
 *  Images widget class (deprecated) 
 */
 
	var fancy = {version : '0.3.2'
		, images 	: ''
		, defaults : {
			'zoomSpeedIn'		: 300, 
			'zoomSpeedOut'		: 300, 
			'overlayOpacity'	: 0.3,
			'hideOnContentClick': false,
			'overlayShow'		: true,
            'padding'           : 0,
            'overlayColor'      : '#fff',
            'titleShow'         : false,
            'cyclic'            : true
		}
		, render : function (options) {var self = this;
			self.options = jQuery.extend({}, self.defaults, options || {});
		    self.images 	= jQuery('.fancy');
			self.load();
		return true;}	
		, load : function (block) {var self = this;
			var images = (typeof(block) == 'object')  ?  block.find('.fancy') : fancy.images;
			if (jQuery.isFunction(jQuery.fn.fancybox))
				images.fancybox(fancy.options);
		}
	}


/* Objects */	

var Objects = {version : '0.0.1'
	, render : function() {
        
        jQuery('div.objects').find('.item').mouseover(function(){jQuery(this).addClass('item-hover')});
        jQuery('div.objects').find('.item').mouseout(function(){jQuery(this).removeClass('item-hover')});
	} 
}	

/* Faq */	
var Faq = {
	  version : '0.0.5'
	
	, preloader : '<img src="templates/common/images/ajax.gif" alt="loading..." />'
		
	, Init : function() {
		Faq.InitLoadGroup();
		Faq.InitShowToggle();
		Faq.InitSubmit();
		
		jQuery('#faqDataCat').change(function(){
			jQuery('#catName').html(jQuery('#faqDataCat option:selected').html());
			jQuery('#catImage').attr('src',jQuery('#image-'+ jQuery('#faqDataCat').val()).html());
		
		return false;});
	}

	, InitLoadGroup : function () {
		jQuery('.faqControlItem').bind('click', function() {
			var data = 'faqLoadGroup=true';
			jQuery('#faqControl').html(Faq.preloader);
			Ajax.query (this.href, '#faqblock', data, 'POST', false, function (block, response) {
				Faq.InitLoadGroup();
			}, jQuery('#faqblock').html());
			
			return false;
	    });
	}
	
	, InitSubmit : function() {
		jQuery('#faqFormContainer').attr('onsubmit', 'return Faq.SubmitForm(jQuery("#faqFormContainer").attr("action"));');
	}

	, InitShowToggle : function() {
		jQuery('.faqFormShow').bind('click', function() {
			if(this.className == 'faqFormShow') {
				Faq.FormShow();
			} else {
				Faq.FormHide();
			}
			return false;
		});
		jQuery('.faqFormShow').show();
	}

	, FormShow : function() {
		//jQuery('.faqFormShow').html('<span>Скрыть</span>');
		jQuery('.faqFormShow').attr('class', 'faqFormHide');
		jQuery('#faqformcontent').show();
	}

	, FormHide : function() {
		//jQuery('.faqFormHide').html('<span>Задать вопрос</span>');
		jQuery('.faqFormHide').attr('class', 'faqFormShow');
		jQuery('#faqformcontent').hide();
	}

	, SubmitForm : function(action) {
		var faqData = Faq.CheckForm();
		/*
		if(faqData != false) {
			Ajax.query (action, '#faqform', faqData, 'POST', false, function (block, response) {
				Faq.InitShowToggle();
				Faq.InitSubmit();
				Faq.FormShow();
			}, jQuery('#faqform').html());
		}
		*/
		return true;
	}
	
	/* TODO: Заменить самописную функцию на валидатор форм на jQuery */
	, CheckForm : function() {
		var isValid = true;
		var dataCollection = 'faqDataSubmit=1';
		jQuery('#faqDataNameErr').html('&nbsp;');
		jQuery('#faqDataEmailErr').html('&nbsp;');
		jQuery('#faqDataQuestionErr').html('&nbsp;');
		jQuery('#faqDataImageErr').html('&nbsp;');
		
		var faqName = jQuery('#faqDataName').val();
		var faqEmail = jQuery('#faqDataEmail').val();
		var faqQuestion = jQuery('#faqDataQuestion').val();
		var faqImage = jQuery('#faqDataImage').val();

		if(faqName == '') {
			jQuery('#faqDataNameErr').html('заполните данное поле');
			isValid = false;
		} else {
			dataCollection += '&faqDataName='+faqName;
		}
		if(faqQuestion == '') {
			jQuery('#faqDataQuestionErr').html('заполните данное поле');
			isValid = false;
		} else {
			dataCollection += '&faqDataQuestion='+faqQuestion;
		}

		if(faqImage == '') {
			jQuery('#faqDataImageErr').html('введите код');
			isValid = false;
		} else {
			dataCollection += '&faqDataImage='+faqImage;
		}

		
		if(faqEmail == '') {
			jQuery('#faqDataEmailErr').html('заполните данное поле');
			isValid = false;
		} else {
			if(checkmail(faqEmail) == false) {
				jQuery('#faqDataEmailErr').html('некорректный email');
				isValid = false;
			} else {
				dataCollection += '&faqDataEmail='+faqEmail;
			}
		}


		return ((isValid == true) ? dataCollection : false);
	}
}


/* Gallery */	
var Projects = {
	  version : '0.0.1'
	  
	, exist : false
	
	, Init : function() {
		if(jQuery('.projectLink').size() > 0) {
			jQuery('.projectLink').click(function(){
				var currentId = jQuery(this).attr('id');
				if (jQuery('#'+currentId+'-cont:visible').size() > 0) {
					jQuery('#'+currentId).removeClass('close');
					jQuery('#'+currentId).addClass('open');
					jQuery('#'+currentId+'-cont').slideUp('slow');
				} else {
					jQuery('#'+currentId).removeClass('open');
					jQuery('#'+currentId).addClass('close');
		
					jQuery('#'+currentId+'-cont').slideDown('slow');
				}
			return false;})
		}
		
	} 
}	



/* Gallery */	
var Gallery = {
	  version : '0.0.1'
	  
	, exist : false
	
	, Init : function() {
		if(jQuery('#GalleryItemImage').size() > 0) { Gallery.exist = true;}
		if(Gallery.exist == true) { Gallery.GenItem(GalleryImagesList[0]);}
	} 
	
	, GenItem : function(item) {
		jQuery('#GalleryItemImage').html(Gallery.GetImageLarge(item));
		jQuery('#GalleryItemTitle').html(Gallery.GetImageTitle(item));
		jQuery('#GalleryItemDescription').html(Gallery.GetImageDescription(item));
		jQuery('#GalleryItemRoofing').html(Gallery.GetImageRoofing(item));
		jQuery('#GalleryItemDecoration').html(Gallery.GetImageDecoration(item));
	} 
	
	, GetImageLarge : function(item) {
		var sizeItem = (item.imageLargeSize).split('-');
		return '<a href="imageview/'+item.imageId+'" target="_blank"><img width="'+sizeItem[0]+'" height="'+sizeItem[1]+'" src="' + item.imageLarge + '" alt="' + item.imageTitle + '" /></a>'
	}
	, GetImageTitle : function(item) {
		return item.imageTitle;
	}
	, GetImageDescription : function(item) {
		return '<span>Разрешение: '+item.imageScreen+'</span>&nbsp;&nbsp;&nbsp;<span>Разрешение: '+item.imageSize+'</span>';
	}
	, GetImageRoofing : function(item) {
		return '<span>Кровля:</span> '+item.roofing;
	}
	, GetImageDecoration : function(item) {
		return '<span>Отделка:</span> '+item.decoration;
	}
	  
	, CarouselInitCallback : function(carousel) {
		jQuery('#GalleryCarouselNext').bind('click', function() {
	        carousel.next();
	        return false;
	    });
	
	    jQuery('#GalleryCarouselPrev').bind('click', function() {
	        carousel.prev();
	        return false;
	    });
	}

	, CarouselItemVisibleInCallback : function(carousel, item, i, state, evt) {
		var idx = carousel.index(i, GalleryImagesList.length);
        carousel.add(i, Gallery.getItemHTML(GalleryImagesList[idx - 1], idx-1 ));
	}

	, CarouselVisibleOutCallback : function(carousel, item, i, state, evt) {
		carousel.remove(i);
	}
	
	, getItemHTML : function(item, idx) {
		var sizeItem = (item.imageSmallSize).split('-');
		return '<a href="#" onclick="Gallery.GenItem(GalleryImagesList['+idx+']); return false;"><img src="' + item.imageSmall + '" width="'+sizeItem[0]+'" height="'+sizeItem[1]+'" alt="' + item.imageTitle + '" /></a>';
	}
}


/**
 * Set opacity style for elements, which have style like 'opacity-15'
 * 
 * @return bool
 */

function setOpacity () {
	
	jQuery("[class*='opacity']").each(function (i) {
		var opacityValue = this.className.substr(this.className.indexOf('opacity-') + 'opacity-'.length, 2);
		if (jQuery.browser.msie) {
			jQuery(this).css('filter',jQuery(this).css('filter') + ' progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacityValue+')');
		} else {
			jQuery(this).css('opacity','.' + opacityValue);
		}
	});
	
	jQuery("[class*='toggle-inputs']").each(function (i) {
		var defaultValue = jQuery(this).val(); 
		jQuery(this).bind("click", function(){
			if (jQuery(this).val() == defaultValue) {
				jQuery(this).val('');
			}
		});

		jQuery(this).bind("focus", function(){
			if (jQuery(this).val() == defaultValue) {
				jQuery(this).val('');
			}
		});

		jQuery(this).bind("blur", function(){
			if (jQuery(this).val() == '') {
				jQuery(this).val(defaultValue);
			}
		});

	});
	
	return true;
}

function setButtons () {
	
	jQuery('button').bind('mouseover', function (i) {
		jQuery(this).addClass('button-hovered');
	});
	jQuery('button').bind('mouseout', function (i) {
		jQuery(this).removeClass('button-hovered');
	});
	
	return true;
}

var Utilites = {		
	  version : '0.0.1'
	  
	, scrollToContent : function () {
		window.scrollTo(0,231);
	}
}

/* Common */
	/* Repair IE footer bug */
	repairTroubleWithJS = function () {
		document.body.style.fontSize = 68 + Math.random()/6 + 0.75 + '%';
	}
	/* Refresh code */
	refreshCodeImage = function () {
		jQuery('#codeimageChangeable').attr('src', 'codeimage/'+Math.random());
	}
	/* Print page */
	printit = function () {
		if(window.print) window.print(); return false;
		var WebBrowser = '<object id="WebBrowserPrint" width="0" height="0" classid="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
		WebBrowserPrint.ExecWB(6, 2);
	}
	/* Check Email */
	checkmail = function (email) { 
		var at = email.indexOf("@"); 
		if (at == -1) return false; 
		if (email.indexOf(".") == -1) return false; 
		if ((at < 1) || (at > email.length - 5)) return false;  
		if ((email.charAt(at - 1) == '.') || (email.charAt(at + 1) == '.')) return false; 
		return true;
	} 
	/* Pages */
	function go (goHref, goBlock) {
		MyUserFunction = repairTroubleWithJS;
		
		jQuery('#pages').html('<img src="templates/common/images/ajax.gif" alt="loading..." />');

		if (goHref.search(/poll/i) != -1) {
			Ajax.query (goHref, '#'+goBlock, '', 'POST', true, function (block, response) {
				News.Init();
			}, jQuery('#'.goBlock).html());
		} else {
			Ajax.query (goHref, '#'+goBlock, '', 'POST', false, function (block, response) {
				News.Init();
			}, jQuery('#'.goBlock).html());
		}
		
		
	}


/* Text tabs function */
	function hideTabElement(id) {jQuery('#'+id).css('display', 'none');}
	
	function hideAllTabElements() 
	{
		jQuery('.tab-text').each(function() {
			this.style.display = 'none';
			jQuery('#link-'+this.id).attr('class', '');
		});
	}
	
	function toggleTabElement(id)
	{
		hideAllTabElements();
		if (jQuery('#'+id).css('display') == 'none') {
			jQuery('#'+id).css('display', '');
			jQuery('#link-'+id).attr('class', 'link-hovered');
		} else {
			jQuery('#'+id).css('display', 'none');
			jQuery('#link-'+id).attr('class', '');
		}
	}

/* News */
var News = {

	  version	: '0.0.1'
	
	, preloader : '<img src="templates/common/images/ajax.gif" alt="..." />'
	  
	, Init : function() {
		jQuery('.newsFiltersItem').bind('click', function() {
			jQuery('#yearNews').html(News.preloader);
			Ajax.query (this.href, '#newsblock', '', 'POST', false, function (block, response) {
				News.Init();
			}, jQuery('#newsblock').html());
			return false;
		});  
	}

}

/* Flash ajax */

var Flash = {
    
    version   : '0.1',
    preloader : '<img src="templates/common/images/ajax.gif" alt="..." />',
    design    : 'default',
    url       : '',
    next_src  : 'vesta_new.swf',
    prev_src  : 'pearl.swf',
    next_link : 'vesta',
    prev_link : 'pearl',
    timer     : 0,
    flags     : true,
    
    Query     : function( type ) {
       var data = 'flash_ajax=' + type;
       Ajax.query(Flash.url, '#ajax_flash', data, 'POST', true, function (block, response) {Projects.Init();}, 
        Flash.preloader + jQuery('#ajax_flash').html());
    },
    
    NextClick : function (){
        Flash.Query('next');
        $('#top-flash').empty().flash(
        { src: 'templates/'+ Flash.design +'/images/flash/' + Flash.next_src,
          width: 761,
          quality: 'high',
          wmode: 'transparent',
          update: true,
          height: 490 },
        { version: 8 }
        ); 
        $('#top-link').attr('href',Flash.next_link);
        
        if ( Flash.flags )
          {
             clearTimeout(Flash.timer);
             setTimeout(function() {Flash.PrevClick();}, 20000);
          }
        
        $('#next').css('display', 'none');
        $('#prev').css('display', 'block');
    },
    
    PrevClick : function (){
        Flash.Query('prev');
        $('#top-flash').empty().flash(
        { src: 'templates/'+ Flash.design +'/images/flash/' + Flash.prev_src,
          width: 791,
          quality: 'high',
          wmode: 'transparent',
          update: true,
          height: 490 },
        { version: 8 }
        );
        $('#top-link').attr('href',Flash.prev_link);
        
        if ( Flash.flags )
          {
             clearTimeout(Flash.timer);
             setTimeout(function() {Flash.NextClick();}, 45600);
          }
        
        $('#next').css('display', 'block');
        $('#prev').css('display', 'none');
    },
    
    
    Init      : function() {
        $('#top-flash').flash(
            { src: 'templates/'+ Flash.design +'/images/flash/' + Flash.prev_src,
              width: 791,
              quality: 'high',
              wmode: 'transparent',
              height: 490 },
            { version: 8 }
            );
           $('#top-link').attr('href',Flash.prev_link);  
         if ( Flash.flags ) Flash.timer = setTimeout(function() {Flash.NextClick();}, 45460);
           
         $('#next').click(function(){
                      
           if ( $('#top-flash embed').attr('src') != 'templates/'+ Flash.design +'/images/flash/' + Flash.next_src )
                Flash.NextClick();
                clearTimeout(Flash.timer);
                Flash.timer = 0;
                Flash.flags = false;
                
             return false;  
         });
         
         $('#prev').click(function(){
            if ( $('#top-flash embed').attr('src') != 'templates/'+ Flash.design +'/images/flash/' + Flash.prev_src )
                Flash.PrevClick();      
                clearTimeout(Flash.timer);
                Flash.timer = 0;
                Flash.flags = false;
              return false;   
         });        
    }
}

/* Menu */
var Menu = {

	  version	: '0.0.1'
	
	, menuTimeOut : 0
	, menuTimeOutMS : 1000
	, bulletTimeOut : 100
	
	, Init : function() {
		jQuery('.menu-item').bind('mouseover', function() {
			jQuery('.submenu').filter('[id!='+this.id+']').hide();
			if (jQuery('#' + this.id + '-submenu').css('display') == 'none') {
				jQuery('#' + this.id + '-submenu').fadeIn();
				jQuery('#' + this.id + '-submenu-bullet').fadeIn();
				clearTimeout(Menu.menuTimeOut);
				clearTimeout(Menu.bulletTimeOut);
			}
            jQuery('#main').css('z-index','1001');
		});
		jQuery('.menu-item').bind('mouseout', function() {
			Menu.bulletTimeOut = setTimeout("jQuery('#" + this.id + "-submenu-bullet').hide();", Menu.bulletTimeOut);
			Menu.menuTimeOut = setTimeout("jQuery('#" + this.id + "-submenu').fadeOut('slow');  ", Menu.menuTimeOutMS);
            jQuery('#main').css('z-index','1');
		});
        jQuery('.menu-item').bind('mouseover', function() {
            $('#prev').css('z-index', -50);
            jQuery('#main').css('z-index','1001');
		});
		jQuery('.submenu').bind('mouseout', function() {
			Menu.bulletTimeOut = setTimeout("$('#prev').css('z-index', 12);jQuery('#" + this.id + "-bullet').hide();", Menu.bulletTimeOut);
			Menu.menuTimeOut = setTimeout("$('#prev').css('z-index', 12);jQuery('#" + this.id + "').fadeOut('slow'); ", Menu.menuTimeOutMS);
            jQuery('#main').css('z-index','1');
		});
		jQuery('.submenu').bind('mouseover', function() {
			clearTimeout(Menu.menuTimeOut);
			clearTimeout(Menu.bulletTimeOut);
            jQuery('#main').css('z-index','1001');
		});
		return true;
	}
}


/* Forms */
var Form = {
	  version : '0.0.1'
	  
	, Validate : function() {
		var error = 0;
				
		jQuery('.xformsValidateEmpty').each(function() {
			var currentId = (this.id).split('-')[1];
			
			jQuery('#error-'+currentId).html('');
			
			if(	(jQuery('#xfield-'+currentId).tagName 	== 'textarea' && jQuery('#xfield-'+currentId).html() == '')	||
			   	(jQuery('#xfield-'+currentId).type 		== 'checkbox' && !jQuery('#xfield-'+currentId).checked)		||
		   		(jQuery('#xfield-'+currentId).val() 	== '')) {
		 		
		 		jQuery('#error-'+currentId).html('заполните данное поле');
		 		
		 		error++;
		 	}
		});
		
		jQuery('.xformsValidateEmail').each(function() {
			var currentId = (this.id).split('-')[1];
			
			if(jQuery('#xfield-'+currentId).val() != '') {
				
				jQuery('#error-'+currentId).html('');
				
				if(checkmail(jQuery('#xfield-'+currentId).val()) == false) {
					jQuery('#error-'+currentId).html('некорректный email');
					error++;
				} 
			}
		});
	
		if (error > 0) {
			return false;
		}
		
		return true; 	
	}
}

/* Ajax handler */	
var Ajax = {
		
	  version			: 	'0.0.1'
	  
	, preloader			:	''
	
	, preloaderInterval	:	''
	
	, preloaderImage	:	'&nbsp;'
	
	, method	:	'POST'
	
	, treads	:	new Object()
	
	, query	:	function (href, block, data, method, noCache, callback, preloader, ajax ) {
 		
		if (Cache.is(href + data) && !noCache) {
			response = Cache.get(href + data);
		
			if (block != '') {
				jQuery(block).html(response);
				if (!preloader) {
					Utilites.scrollToContent();
				}
			}
			if (typeof callback == 'function') {
				callback(block, response);
			}
			return true;
		} 		
		if (Ajax.treads[href + data] != undefined && Ajax.treads[href + data] != false) {
			return true;		
		} else {
			Ajax.treads[href + data] = true;
		}
		
		if (preloader || href == 'authline') {
			if (block != '') {
				jQuery(block).html(preloader);
			}
		} else if (block != ''){
			
		}
		
		preloader 	= (!preloader) 	? Ajax.preloader 	: preloader;
		method 		= (!method) 	? Ajax.method 		: method;
		
        if (!ajax) ajax = '&ajax=true';
        else ajax = ''; 	
        
		jQuery.ajax({
			cache		: true,
			timeout		: 10000,
			dataType	: 'html',
			type		: method,
			url			: href,
			data		: data + ajax,
	
			success: function(response){
				Ajax.treads[href + data] = false;
				if (!noCache){
					Cache.put(href + data, response);
				}
				if (block != '') {
					jQuery(block).html(response);
				}
				if (typeof callback == 'function') {
					callback(block, response);
				}
				return true;
			}
		});
		
		return true;
	}
}
	
	
/* Cache handler */	

var Cache = {

	  version	: 	'0.0.1'
		
	, cacheData : new Object()
	 
		, get 		: function (href) {
		return Cache.cacheData[href];
	}
	
	, is 		: function (href) {
		if (Cache.cacheData[href] != undefined && Cache.cacheData[href] != '') {
			return true;		
		}
		return false;
	}
	
	, put 		: function (href, content) {
		Cache.cacheData[href] = content;
		return true;
	}
	
	, remove	: function (href) {
		Cache.cacheData[href] = '';
		return true;
	}
}

/* Poll */

	function poll (id) {
	
		if (!id) {id = '';}
		
		data = '&pollside=true';
		data = data + '&pollid='+id;
		
		if (jQuery('#pollbutton'+id).size() > 0) {

			data = data + '&p_id='+jQuery('#p_id'+id).val();
			data = data + '&qoa='+jQuery('#qoa'+id).val();

			var elements = document.getElementById('form_poll'+id).elements;
			for (var i = 0; i < elements.length; i++) {
				switch (elements[i].type.toLowerCase()) {
					case 'checkbox':
					case 'radio':
						if (elements[i].checked)
							data = data + '&'+elements[i].name + '=' + elements[i].value;
				}
			}
			jQuery('#pollbutton'+id).html('<img src="templates/common/images/ajax.gif" alt="..." />');
		}
		
		Ajax.query ('side_poll', '#side_poll' + id, data, 'POST', true, function (block, response) {}, jQuery('#side_poll'+id).html());
	}


/* Orders */
var Orders = {

	  version	: '0.0.1'
	
	, preloader : '<img src="templates/common/images/ajax.gif" alt="..." />'
	  
	, Init : function() {
		jQuery('.orderFilterTheme').bind('change', function() {
			jQuery('#orderTheme').html(Orders.preloader);
			Ajax.query (this.value, '#ordersList', '', 'POST', false, function (block, response) {
				Orders.Init();
			}, jQuery('#ordersList').html());
			return false;
		});  
	}

}
