

$(document).ready(function() {

	announce_i = 0;
	announce_speed = 500;
	announce_timeout = 3000;
	announce_first = true;
	announce_parts = new Array;
	announce_href = $;
	announce_ready = false;
	announce_margin = 0;
						   
	if ($.browser.msie && parseInt($.browser.version) < 7) {
		$("body").addClass('fancybox-ie ie6');}
						   
	$("a[rel=fancybox]").fancybox();
	$("a.fancybox").fancybox();
	$("a.iframe").removeAttr('target').fancybox({	"frameWidth": 1024,
													"frameHeight": 768,
													"width": 1024,
													"height": 768});
													
	bodyBlock = $("body");
	resizedElements = $("#slideShow_list, #slideShow_frameTopBorderContainer, #workplace, #main #menuPlaceInner, #main #menuPlaceInner, #slideShow_containerOuter, #slideshowFlashPlaceInner, #slideShow_list");
	
	/*if ($.browser.msie == true && parseInt($.browser.version) < 7) {
		setInterval(function(){
			var bodyWidth = parseInt(bodyBlock.outerWidth());
			if (bodyWidth > 1280) {
				resizedElements.css({'width':'1280px'});
			} if (bodyWidth < 999) {
				resizedElements.css({'width':'999px'});
			} else {
				resizedElements.removeAttr('style');
			}
		}, 300);
	}*/

	announce_href = $("#slideShow_list li");
	
	function showNextHidePrev(){
		
		if (announce_i+1 < announce_parts.length) {
			var image = announce_parts[announce_i+1].find("img"); }
		else {
			var image = announce_parts[0].find("img"); }
			
		announce_margin = Math.abs(Math.round((image.outerHeight() - 215) / 2));
		image.css({'marginTop': -announce_margin+'px'});
		
		if (announce_i+1 < announce_parts.length) {
			announce_parts[announce_i+1].animate({'opacity':'1'}, announce_speed, function(){
				announce_parts[announce_i].css({'opacity':'0'});
				announce_margin = announce_margin/2;
				if (announce_i%2 != 0) {
					image.animate({'marginTop':'0px'}, announce_timeout/2);}
				else {
					image.animate({'marginTop': -(announce_margin*4) + 'px'}, announce_timeout); }

				announce_i++;
				setTimeout(showNextHidePrev, announce_timeout);
			});
		}else{
			announce_parts[0].animate({'opacity':'1'}, announce_speed);
			announce_parts[announce_i].animate({'opacity':'0'}, announce_speed, function(){
				announce_i = 0;
				announce_margin = announce_margin/2;
				if (announce_i%2 != 0) {
					image.animate({'marginTop':'0px'}, announce_timeout/2);}
				else {
					image.animate({'marginTop': -(announce_margin*4) + 'px'}, announce_timeout); }
				setTimeout(showNextHidePrev, announce_timeout);
			});
		}
	}
	
	function toggleFadeAnnounce() {
		if (!(announce_ready)) {
			for (i = 0; i < announce_href.size(); i++) {
				announce_parts[i] = $(announce_href[i]);
			}
			
			var announce_i = 0;
			var announce_first = true;
			for (i = 0; i < announce_parts.length; i++) {
				if (!(announce_first)) {
					announce_parts[i].css({'opacity':'0'});
				}
				announce_first = false;
			}
			announce_ready = true;
		}
		announce_parts[0].css({'opacity':'1'});
	}
	
	imageSrcList = new Array();
	i = 0;
	
	announce_href.each(function(){
		var image = $(this).find("img");
		var src = image.attr('src');
		var margin = Math.abs(Math.round((image.outerHeight() - 215) / 2));
		
		image.css({'marginTop':	-margin + 'px'});
		
		imageSrcList[i] = new Image();
		imageSrcList[i].src = src;
	});
	
	toggleFadeAnnounce();
	showNextHidePrev();

});
