// JavaScript Document

$(document).ready(function(){
						   
	var backgroundBottom = $("#backgroundBottom");
	var workplace = $("#workplace");
	var footer = $("#footer");
	
	function setElementsPosition(){
		backgroundBottom.removeAttr('style');
		
		var windowHeight = $(window).height();
		var backgroundBottomHeight = backgroundBottom.height();
		
		if (backgroundBottomHeight < windowHeight) {
			if (windowHeight < 730) {
				backgroundBottom.css({'height':	'730px'});}
			else {
				backgroundBottom.css({'height':	windowHeight+'px'});}
		}else{
			if(backgroundBottomHeight < 730) {
				backgroundBottom.css({'height':	'730px'});}
		}
	}
	
	if ($.browser.msie && $.browser.version < 7) {}
	else {
		var resizeTimeoutId = false;
	
		$(window).resize(function(){
			if (resizeTimeoutId) {
				clearTimeout(resizeTimeoutId);}
			resizeTimeoutId = setTimeout(function(){setElementsPosition();}, 10);
		});
		
		setElementsPosition();
	}

	var photoGalery = $("#photoGalery");
	var imageNum = 1;
	var curentImg = "";
	var img = "";
	
	function slideImage(){		
		curentImg = photoGalery.children('img');
		
		if (imageNum < imageArray.length) {
			newImage = new Image();
			newImage.src = imageArray[imageNum];
			
			img = $(newImage);
			img.addClass('hiddenImg');
			photoGalery.prepend(img);
			/*img.ifixpng(); это нужно лишь для png */ 
		}
			
		setTimeout(	function(){
						curentImg.animate({'opacity':'0'}, 500,	function(){
																		img.removeClass('hiddenImg');
																		if (imageNum < imageArray.length - 1) {
																			imageNum++;}
																		else {
																			imageNum = 0;}
																		curentImg.remove();
																		slideImage();
																});
					}, 2000);
	}
	
	if (photoGalery.size()) {
		slideImage();}
	
	$("form input").focus(function(){
		$(this).addClass('focus');
	});
	$("form input[type=text]").blur(function(){
		if (this.value == '') {
			$(this).removeClass('focus');}
	});
	
	$("form input").blur(function(){
		//$(this).removeClass('focus');
	});
	
	/* $(".roundTop, .roundBottom, #footer .leftRound, .centerRound, .rightRound, .promoBlock .roundCenter, .bannerBottomHeader, img").ifixpng();
	 * 
	 * заменено на */
	if ($.browser.msie == true && $.browser.version <= 6) {
        $(".roundTop, .roundBottom, #footer .leftRound, .centerRound, .rightRound, .promoBlock .roundCenter, .bannerBottomHeader, img").ifixpng();
    }
	
	
	document.onkeydown = NavigateThrough;
	
	$("a[rel^='fancybox']").fancybox({
        /*'transitionIn'  :   'elastic',
        'transitionOut' :   'elastic',*/
        'speedIn'       :   400, 
        'speedOut'      :   400, 
        'overlayShow'   :   true,
        'titlePosition' :   'outside'/*,
        'titleFormat'   :   function(title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">' + title + '</span>';
        }*/ 
    });
});

function NavigateThrough (event) {
    if (!document.getElementById) {
        return;
    }    
    if (window.event) {
        event = window.event;
    }
    if (event.ctrlKey) {
            var link = null;
            var href = null;
            switch (event.keyCode ? event.keyCode : event.which ? event.which : null) {
                case 0x27:
                    link = document.getElementById ('NextLink');
                    break;
                case 0x25:
                    link = document.getElementById ('PrevLink');
                    break;
            }
        if (link && link.href) {
            document.location = link.href;
        }
        if (href) {
            document.location = href;
        }
    }                       
}

















