/* flash */

var params = {
  	menu: "false",
  	scale: "noScale",
	wmode: "transparent"
};

swfobject.embedSWF("/i/banners/02.swf", "bright_life_flash", "680", "260", "9.0.0", "", {}, params);
swfobject.embedSWF("/i/banners/01.swf", "product_flash", "680", "260", "9.0.0", "", {}, params);
swfobject.embedSWF("/i/banners/03.swf", "aquabionica_flash", "680", "260", "9.0.0", "", {}, params);
swfobject.embedSWF("/i/banners/04.swf", "business_flash", "680", "260", "9.0.0", "", {}, params);
swfobject.embedSWF("/i/banners/box.swf", "box_flash", "680", "200", "9.0.0", "", {}, params);

params.scale = "scale";
swfobject.embedSWF("/i/banners/moleculas.swf", "moleculas_flash", "483", "297", "9.0.0", "", {}, params);



$(function(){

/* // menu width :)
var width = 0;
var menu = [];
$('#menu a').each(function(){
	menu.push($(this).width());
	width += $(this).width();
});

var pad = Math.floor((922 - width) / 4);
var css = '';
var pre = '#' + $('body').attr('id') + ' #menu';
var mid = ' {width:';
var post = 'px;}' + "\n";
for (var i = 0; i < menu.length; i++) {
	if (i == 4)
	    css += pre + (i + 1) + mid + menu[i] + post;
	else
	    css += pre + (i + 1) + mid + (menu[i] + pad) + post;
}
alert(css);
*/


/* ie6 fixes */
if ($.browser.msie && $.browser.version < 7) {
        $.ifixpng('/i/blank.gif');
        $('img').ifixpng();
	$('.zebra-hoverable tr').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});
}

/* print */
$('a.print-scheme, a.print').click(function(){
	window.print();
	return false;
});

/* rel=blank */
$('a[rel=blank]').click(function(){
	window.open($(this).attr('href'));
	return false;
});

/* popups */
function hidePopups(e){
	var trgt = e.target;
        var curElements = $('.popup:visible').find('*').andSelf();
        if ($.inArray(trgt, curElements) < 0) {
        	$('.popup').hide();
		$(document).unbind('mousedown', hidePopups);
        }
	return true;
};

$('.close', '.popup').click(function(){
	$(this).parents('.popup').hide();
	$(document).unbind('mousedown', hidePopups);
	return false;
});

/* languages popup */
$('.r, .l', '#form-lang').css({
	cursor: 'pointer'
}).click(function(){
	$('.popup', '#form-lang').show();
	$(document).bind('mousedown', hidePopups);
});


/* search field value */
var search_default = $('#query').val();
$('#query').focus(function(){
	if ($(this).val() == search_default)
		$(this).val('');
}).blur(function(){
	if ($(this).val() == '')
		$(this).val(search_default);
});

/* ceo */
if ($('.ceo-gal').length) {
	var $fade = $('.fade', '.ceo-gal');
	if (!$fade.length) { 
		$('.ceo-gal').append('<div class="fade"></div>');
		$fade = $('.fade', '.ceo-gal');
		$fade.css({
		    opacity: 1,
		    display: 'none'
		});
	}
	
	var $all = $('.ceo-gal .all');
	var $cur = $('.ceo-gal .cur');
	var $allquot = $('.ceo-gal .allquot');
	var $curquot = $('.ceo-gal .curquot'); 

	var width = $('.ceo-gal').width();
	$allquot.width(width);
	var maxheight = 0;
	$('div', $allquot).each(function(){
		maxheight = Math.max($(this).height(), maxheight);
	});
	if ($.browser.msie) {
		$curquot.css({
			display:'inline',
			zoom: 0
		});
		$('.ceo-gal').height(
			$('.ceo-gal').height()
			- $curquot.height()
			+ maxheight + 10
		);
	} else {
		$curquot.height(maxheight + 10);
	}

	setInterval(function(){
		$fade.css({
		    opacity: 0,
		    display: 'block'
		}).animate({
		    opacity: 1
		}, 100, function(){
			var $show = $('div.show', $all); 
			
			if ($show.length) {
				$next = $show.next('div');
				if (!$next.length)
					$next = $('div:eq(0)', $all);
			} else {
				$next = $('div:eq(1)', $all);
			}
			
			$show.removeClass('show');
			$next.addClass('show');
			
			$cur.html($next.html());
			
			$show = $('.show', $allquot);
			if ($show.length) {
				$next = $show.next('div');
				if (!$next.length)
					$next = $('div:eq(0)', $allquot);
			} else {
				$next = $('div:eq(1)', $allquot);
			}
			
			$show.removeClass('show');
			$next.addClass('show');
			
			$curquot.html($next.html());  
			
			$fade.animate({
				opacity: 0
			}, 100, function(){
				$fade.css({
					display: 'none'
				});
			});

			$show = null;
		});
	}, 8000);
}



/* photos */

var photos_noclick = false;

$('.photos, .photo').append('<span class="arrow" />');



$('.paginator', '.photos').each(function(){
	if (! $('.prev', this).length) {
		$(this).prepend('<a href="#" class="prev" />');
	}
	if (! $('.next', this).length) {
		$(this).append('<a href="#" class="next" />');
	}
});

$('.photos p').not('.active p').css({
	visibility: 'visible',
	opacity:    0
});

$('.photos img').not('.active img').css({
	opacity:    0
});

$('.paginator a', '.photos').click(function(){
	if (photos_noclick)
		return false;

	if ($(this).hasClass('active'))
		return false;

	var $photos = $(this).parents('div.photos');
	var $paginator = $('.paginator', $photos);
	var $active = $('.active', $paginator);
	var $a = $('a:not(.prev):not(.next)', $paginator);
	var $li = $('li', $photos); 

	var current = $a.index($active);
	var next    = $a.index(this);

	if ($(this).hasClass('prev'))
		next = current - 1;
	else if ($(this).hasClass('next'))
		next = current + 1;

	if (next < 0 || next >= $li.length)
		return false;

	photos_noclick = true;
	$active.removeClass('active');
	$a.eq(next).addClass('active');
	$current = $li.eq(current);
	$next    = $li.eq(next);
	photos_animate($current, $next)									
	return false;
});

$('img', '.photos').css({cursor:'pointer'}).click(function(){
	if (photos_noclick)
		return false;

	var $photos = $(this).parents('div.photos');
	var $paginator = $('.paginator', $photos);
	var $a = $('a:not(.prev):not(.next)', $paginator);
	var $li = $('li', $photos);
	var current = $li.index($(this).parents('li'));
	var next    = current + 1;
	if (next >= $li.length)
		next = 0;

	photos_noclick = true;

	$('.active', $paginator).removeClass('active');
	$a.eq(next).addClass('active');
	
	$current = $li.eq(current);
	$next    = $li.eq(next);
	photos_animate($current, $next)									
	return false;	
});


function photos_animate($current, $next) {
	$('img, p', $current).animate({
		opacity: 0
	}, 500, function(){
		if ($(this).is('p'))
        		if (this.style.filter && this.style.removeAttribute)
                		this.style.removeAttribute('filter');
	});

	$('img, p', $next).animate({
		opacity: 1
	}, 500, function(){
		if ($(this).is('p'))
			if (this.style.filter && this.style.removeAttribute)
                		this.style.removeAttribute('filter');
		photos_noclick = false;
		$current.removeClass('active');
		$next.addClass('active');
		$('.photos p').not('.active p').css({
			opacity:    0
		});
	});
}

/* zebra-cross */
$('td:not(.empty)', '.zebra-cross:not(.nohighlight)').hover(function(){
	$(this).addClass('hover cross');
	$(this).prevAll('td, th').addClass('hover');

	// отсчет ячеек - справа
	var $tr = $(this).parents('tr');
	var $cells = $('th, td', $tr);  
	var from_right = $cells.length - $cells.index(this);

	$tr.prevAll('tr')
		.add($('thead tr', $(this).parents('.zebra-cross')))
		.each(function(){
			var $tr = $(this);
			var $cells = $('th, td', $tr);
			$cells.eq($cells.length - from_right).addClass('hover');
		});
}, function(){
	$('.hover', $(this).parents('.zebra-cross')).removeClass('hover');
	$(this).removeClass('cross');
});

/* highlighted table #scheme */
 $('#scheme  p').mouseover(function(){
 	var overedClass = $(this).attr( 'class' )
	if (overedClass =='r1 r2 r3 r4'){
		$('.r1, .r2, .r3, .r4').css('color','red')
	}
	if (overedClass =='r7 r8'){
		$('.r7, .r8,').css('color','red')
	}
	if (overedClass =='r1 r2'){
		$('.r1, .r2,').css('color','red')
	}
	if (overedClass =='r5 r6'){
		$(' .r5, .r6').css('color','red')
	}
	$('.' + overedClass).css('color','red')
  }).mouseout(function(){
	$('#scheme  p').css('color','#4d4d4d')
  });

/* pilot */
$('.blue-trigger-handler').hover(function(){
	$('#pilot').show();
}, function(){
	$('#pilot').hide();
});
$('.green-trigger-handler').hover(function(){
	$('#navigator').show();
}, function(){
	$('#navigator').hide();
});
$('.red-trigger-handler').hover(function(){
	$('#comandor').show();
}, function(){
	$('#comandor').hide();

});
$('.trigger-handler').hover(function(){
	$(this).css('background-position', 'left -26px')
	$(this).children('a').css('background-position', 'right -26px')
}, function(){
	$(this).css('background-position', 'left top')
	$(this).children('a').css('background-position', 'right top')
});

$('.red-trigger-handler a, .blue-trigger-handler a, .green-trigger-handler a').click(function(){
	return false;
});

/* accordeon toggle */
$('.accordeon-toggle').click(function(){
	$(this).parents('h4').next('.accordeon').toggle('fast');
	return false;
});
$('.accordeon-hide a').click(function(){
	$(this).parents('.accordeon').hide('fast');
	return false;
});

/* fancybox */
$('.gallery a').fancybox({
	'hideOnContentClick': false,
	'padding': 0
});

$('a.movie').fancybox({
	'hideOnContentClick': false,
	'frameWidth': 880,
	'frameHeight': 660,
	'padding': 0
});


});


var mark = new Array(),
    map,mparam=new Object();

mparam.lat=55.73764553509855;
mparam.lng=37.491295337677;
var html = '<strong><img src="/i/contacts/logo.jpg" alt="" style="vertical-align:middle;"/>&nbsp;Aquabionica&nbsp;Corp.</strong><br />Россия, Москва,<br />улица Кастанаевская, 17<br /><img style="margin: 5px auto 0;display:block;" src="/i/contacts/rus-pic.jpg" alt="" width="100" height="67" />';

function loadMap() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("googlemap"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        
        var point = new GLatLng(mparam.lat, mparam.lng);
        map.setCenter(point, 16, G_NORMAL_MAP);
        
	createMarker(point, html, {});
    }
}

function createMarker(mpoint, tooltip, opts) {
    if (!map) return null;

    mark.push(new GMarker(mpoint, opts));

    GEvent.addListener(mark[mark.length - 1], "click", function() {
        var str = String(tooltip);
        this.openInfoWindowHtml(str);
    });

    map.addOverlay(mark[mark.length - 1]);
    mark[mark.length - 1].openInfoWindowHtml(tooltip);
    return mark[mark.length - 1];
}
