$(document).ready(function () {

	/*var flashvars = {};
	var params = {wmode: "transparent"};
	var attributes = {};
	var bHeight = $(document).height();
	swfobject.embedSWF("/swf/map.swf", "map", "300px", "290px", "9.0.0" ,"/swf/expressInstall.swf", flashvars, params, attributes);

		var flashvars = {};
		var params = {wmode: "transparent"};
		var attributes = {};
		var bHeight = $(document).height();
		swfobject.embedSWF("/swf/bmap.swf", "bmap", "980px", "396px", "9.0.0" ,"/swf/expressInstall.swf", flashvars, params, attributes);
	*/

	theRotator();
	
	if($('.geoBlock').length>0){
		$('.geoBlock').hide();
		$('#about').show();
	}
	
	$("#sendcont .slide").click(function(){
		$(this).parent().parent().children('div.spl').slideToggle("fast");
		return false;
	});

	
	/* загрузчик */

	if($('#offerta_btn').length > 0){
		BindSWFUploadOfferta();
	}
	if($('#offerta_btn_ind').length > 0){
		BindSWFUploadOffertaInd();
	}
	
	// onFocus
	$('#search .s').focus(function(){
		if($(this).val() == 'Поиск по сайту'){$(this).val('').addClass('focus');}
	});
	$('#search .s').blur(function(){
		if($(this).val() == ''){$(this).val('Поиск по сайту').removeClass('focus');}
	});	
	
	// Вакансии
		$("#send .slide").click(function(){
		$(this).parent().parent().children('div.spl').slideToggle("fast");
		return false;
	});
	/*
	$("#send").click(function(){
		if ($("form.feedback").hasClass("active")){
			$("form.feedback").removeClass("active");
			}else{
			$("form.feedback").addClass("active");
			};
		return false;
	});
	*/

	/* Colorbox */
	$("a[rel='gal']").colorbox({opacity:0.5, scalePhotos:true, maxWidth:"90%", maxHeight:"90%", current:"{current} / {total}", slideshow:false, slideshowAuto:false, slideshowStart:"начать слайдшоу", slideshowStop:"остановить слайдшоу"});
	$("a.gal").colorbox({opacity:0.5, scalePhotos:true, maxWidth:"90%", maxHeight:"90%", current:"{current} / {total}"});
	$("a[rel='sert']").colorbox({opacity:0.5, scalePhotos:true, maxWidth:"90%", maxHeight:"90%", current:"{current} / {total}", slideshow:false, slideshowAuto:false, slideshowStart:"начать слайдшоу", slideshowStop:"остановить слайдшоу"});
	
	$(".col").click(function(){
		$(this).hide();
	});
	
	$("#myslidemenu li").click(function(){
		$(".col").hide();
	});
}); // end ready

/* РеАктив*/
var ShowReaktiveFlag = false;

function ShowReaktiveStart(){ ShowReaktiveFlag = true; setTimeout("ShowReaktive()",50); }
function ShowReaktive(){
	if ((ShowReaktiveFlag) && ($("#reaktive_block").css('display')=='none')){
		$("#reaktive_block").css({display: "block"});
		$("#reaktive_block IMG").css({width: 0, height: 0, right: "70px", top: "0px"});
		$("#reaktive_block IMG").animate({width: 274, height: 131, right: -4, top: -102}, 200);
	}
}

function HideReaktiveStart(){ ShowReaktiveFlag = false; setTimeout("HideReaktive()",50); }
function HideReaktive(){
	if ((!ShowReaktiveFlag) && ($("#reaktive_block").css('display')!='none')){
		if ($.browser.msie) $("#reaktive_block").css('display','none');
		else $("#reaktive_block").fadeOut(300);
	}
}

/* Меню */
var isAtMenu;
var colCount;
var multiCol = false;

var jqueryslidemenu={
animateduration: {over: 150, out: 100}, //duration of slide in/ out animation, in milliseconds
buildmenu:function(menuid, arrowsvar){
	$(document).ready(function($){
		var mainmenu=$("#"+menuid+">ul")
		var headers=mainmenu.find("ul").parent()
		headers.each(function(i){
			var curobj=$(this)
			var subul=$(this).find('ul:eq(0)')
			this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:subul.outerWidth(), subulh:subul.outerHeight()}
			this.istopheader=curobj.parents("ul").length==1? true : false
			subul.css({top:this.istopheader? this._dimensions.h+"px" : 0})
			curobj.hover(
				function(e){
					$(this).children('a').addClass('hover');
					var targetul=$(this).children("ul:eq(0)")
					this._offsets={left:$(this).offset().left, top:$(this).offset().top}
					var menuleft=this.istopheader? 0 : this._dimensions.w
					menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft
					//Buben mode: on
					if(!targetul.hasClass('col')){
					
						if (targetul.queue().length<=1) //if 1 or less queued animations
							targetul.css({left:menuleft+"px", width:this._dimensions.subulw+'px', height:'auto'}).show(); //slideDown(jqueryslidemenu.animateduration.over)
					}else{
						multiCol = true;
						var colCount = 0;
						targetul=$(this).children('ul');
						var max = 0;
						var maxHeight = 0;
						targetul.each(function (){
							colCount++;
							if(colCount > 1){$(this).children('a').css({'padding-right':'10px'});}
							if(max < $(this).width()){max = $(this).width();}
							if(maxHeight < $(this).height()){maxHeight = $(this).height();}
						});
						var i = 0;
						if ($.browser.msie && $.browser.version.substr(0,1) < 7) {
						}
						targetul.each(function(){
							$(this).css({width:max,height:maxHeight, left:i*max, top:35});
							$(this).show(); //.slideDown(jqueryslidemenu.animateduration.over);
							i++;
						});
					}
				},
				function(e){
					$(this).children('a').removeClass('hover');
					if(!multiCol){
						var targetul=$(this).children("ul:eq(0)")
						targetul.hide(); //.slideUp(jqueryslidemenu.animateduration.out)
					}else{
						targetul=$(this).children('ul');
						targetul.hide(); //.slideUp(jqueryslidemenu.animateduration.out)
					}
				}
			) //end hover
			curobj.click(function(){
				$(this).children("ul:eq(0)").hide()
			})
		}) //end headers.each()
		mainmenu.find("ul").css({display:'none', visibility:'visible'})
	}) //end document.ready
}
}

//build menu with ID="myslidemenu" on page:
jqueryslidemenu.buildmenu("myslidemenu")

// визуал
function theRotator() {
	$('div.visual ul li').css({opacity: 0}).hide();
	$('div.visual ul li.show').css({opacity: 1}).show();
	rotateVar = setInterval('rotate()',5000)	
}
var current = "";
var next = "";
var visualhideVar;
function rotate() {	
	clearInterval(rotateVar);
	current = $('div.visual ul li.show');
	next = ((current.next().length) ? current.next() : $('div.visual ul li:first'));	
	
	if (!(current.next().length)) {
		next.addClass('show').show().css({zIndex:2}).animate({opacity:1},800);
	} else {
		next.addClass('show').show().animate({opacity:1},800);
	}
 
	visialhideVar = setInterval('visual_hide()',800);
};

function visual_hide() { 
	clearInterval(visialhideVar);
	next.css({zIndex:1})
	current.removeClass('show').css({opacity: 0}).hide();
	rotateVar = setInterval('rotate()',5000)
}

/************* SWF UPLOAD EXAMPLE ***********************/

var PhotosResult = "";
var Count = 0;
var UploadedFiles = 0;
var CountOfferta = 0;
var CountOffertaInd = 0;

function photos_fileDialogComplete(numFilesSelected, numFilesQueued) {
    try {
        if (numFilesQueued > 0) {
            PhotosResult = numFilesQueued == '1' ? ' image' : ' images';
            PhotosResult = numFilesQueued + PhotosResult + " attached";
            Count = parseInt(numFilesQueued);
            $('#AddPhotos').val('Uploading...');
            $('#submitStatus')
                .attr('disabled', 'disabled')
                .addClass('disabled');
            this.startUpload();
        }
    } catch (ex) {
    }
}

//OffertaPhotos
function photos_uploadProgressOffertaPhotos(file, bytesLoaded) {
	if (CountOfferta==0){
		//$('#offerta .hide').hide();
		$('#offerta .loading').show();
		CountOfferta++;
	}
}
function photos_uploadSuccessOffertaPhotos(file, serverData) {
	$('#offerta .loading').hide();
	if ($.browser.msie && $.browser.version.substr(0,1)<=7) {
		$('#offerta .file-path').html("Ваш файл загружен");
	}else{$('#offerta .file-path').html(serverData);}
	$('#offerta .file-path').show();
	$('#offerta .hidden').val(serverData);
}

function photos_uploadProgress(file, bytesLoaded) {
//	$('.loading').show();
    try {
        var pw = 115;
        var w = Math.ceil(pw * (UploadedFiles / Count + (bytesLoaded / (file.size * Count))));
        $('#Progress').stop().animate({ width: w });
    } catch (ex) {
    }
}
function photos_uploadSuccess(file, serverData) {
    try {
        UploadedFiles++;
    } catch (ex) {

    }
}

function photos_uploadComplete(file) {
    try {
        if (this.getStats().files_queued > 0) {
            this.startUpload();
        } else {
            $('#UploadPhotos').hide();
            $('#Buttons').prepend('<span id="UploadResult" class="images">' + PhotosResult + '</span>');
        }
    } catch (ex) {
    }
}
function photos_fileQueueError(file, errorCode, message) {
    try {
        switch (errorCode) {
            case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
                alert('Вы загружаете слишком много файлов');
               break;
            case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
				alert('Файл слишком маленький');
			break;
            case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
				alert('Слишком большой файл');
			break;
            case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
				alert('Маленький файл');
			break;
            case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
				alert('Не правильный тип файла');
            break;
        }
    } catch (ex) {
    }

}

function swfuploadLoaded() {
    $('#Buttons object').hover(
        function() {
            $(this).next().addClass('hover');
        },
        function() {
            $(this).next().removeClass('hover');
        });

}
var ASPSESSID = "";
var swfuPhotos;

function BindSWFUploadOfferta() {
	var swfOffertaPhotosSettings = {
		upload_url: "/inc/upload.php",
        file_dialog_complete_handler: photos_fileDialogComplete,
        upload_progress_handler: photos_uploadProgressOffertaPhotos,
        upload_success_handler: photos_uploadSuccessOffertaPhotos,
        upload_complete_handler: photos_uploadComplete,
        swfupload_loaded_handler: swfuploadLoaded,
        file_queue_error_handler: photos_fileQueueError,
        file_size_limit: "2 MB",
        file_types: "*.doc;*.rtf;*.docx;*.txt;*.odt;*.pdf",
        file_types_description: "Документ MS Office, OpenOffice.org или PDF",
        file_upload_limit: "99",
        button_placeholder_id: "offerta_btn"
    }
    var defaultSettings = {
        flash_url: "/swf/swfupload.swf",
        upload_url: "/inc/upload.php",
        post_params: {
            "ASPSESSID": ASPSESSID
        },
        button_width: 200,
        button_height: 30,
		button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
        button_cursor: SWFUpload.CURSOR.HAND
    }
    swfOffertaPhotos = new SWFUpload($.extend(defaultSettings, swfOffertaPhotosSettings));
};

function geoBlock(obj){
	$('.geoBlock').hide();
	$('#'+obj).show();
}
