$(function() {
	var str = navigator.userAgent;
	if(str.indexOf('Opera') + 1) {
		$('.banners_main ul li').css('padding-right','2px');
	}
});

var windowObjectReference = null;
function openPopUp(oHref, oWidth, oHeight) {

	if (oWidth > 800) oWidth = 800;
        if (oHeight > 600) oHeight = 600;

        var oLeft = (screen.availWidth - oWidth) / 2;
	var oTop = (screen.availHeight - oHeight) / 2;



	//oWidth += 20;
	//oHeight += 20;


	//if(windowObjectReference == null || windowObjectReference.closed) {
		windowObjectReference = window.open(oHref, 'Preview', 'width='+oWidth+',height='+oHeight+',top='+oTop+',left='+oLeft+',menubar=0,toolbar=0,location=0,directories=0,personalbar=0,status=0,resizable=0,scrollbars=0,dependent=0,dialog=0,minimizable=0,fullscreen=0,titlebar=0,close=0');
	//} else {
		windowObjectReference.focus();
	//}
	return false;
}


$(document).ready(function() {
				
				$('table.diagram').css('display', 'none');

				// Menu
				$('ul#my-menu ul').each(function(i) {
					if ($.cookie('submenuMark-' + i)) {
						$(this).show().prev().removeClass('collapsed').addClass('expanded');
					} else {
						$(this).hide().prev().removeClass('expanded').addClass('collapsed');
					}
					$(this).prev().addClass('collapsible').click(function() {
						var this_i = $('ul#my-menu ul').index($(this).next());
						if ($(this).next().css('display') == 'none') {
							$(this).parent('li').parent('ul').find('ul').each(function(j) {
								if (j != this_i) {
									$(this).slideUp(200, function () {
										$(this).prev().removeClass('expanded').addClass('collapsed');
										cookieDel($('ul#my-menu ul').index($(this)));
									});
								}
							});
							$(this).next().slideDown(200, function () {
								$(this).prev().removeClass('collapsed').addClass('expanded');
								cookieSet(this_i);
							});
						} else {
							$(this).next().slideUp(200, function () {
								$(this).prev().removeClass('expanded').addClass('collapsed');
								cookieDel(this_i);
								$(this).find('ul').each(function() {
									$(this).hide(0, cookieDel($('ul#my-menu ul').index($(this)))).prev().removeClass('expanded').addClass('collapsed');
								});
							});
						}
						return false;
					});
				});
				// Flash

				$('.slideshow').cycle({
					fx: 'fade',
					random: 1,
					timeout: 6000,
					before: function() {
						$('#info').html('<'+'a href="'+$(this).attr('href')+'">'+$(this).attr('title')+'</'+'a>');
						Cufon.replace("#info");
					}
				});

				$('table.colorer').find('tr:nth-child(odd)').addClass("odd");

	$('a[href$=.flv]').click(function(){
		return openPopUp('http://'+document.domain+'/?module=media&action=view&filename='+$(this).attr('href'), 400, 300);
	});

        var pathToLightBoxImage = '/images/lightbox';
        $('a[rel=popup]').lightBox({
            overlayBgColor: '#000',
            overlayOpacity: 0.5,
            containerBorderSize: 10,
            txtImage: '№',
            txtOf: '&ndash;',
            imageBtnNext: pathToLightBoxImage + '/lightbox-btn-next.gif',
            imageBtnPrev: pathToLightBoxImage + '/lightbox-btn-prev.gif',
            imageBtnClose: pathToLightBoxImage + '/lightbox-btn-close.gif',
            imageLoading: pathToLightBoxImage + '/lightbox-ico-loading.gif',
            imageBlank: pathToLightBoxImage + '/lightbox-blank.gif'
        });
});

			function cookieSet(index) {
				$.cookie('submenuMark-' + index, 'opened', {expires: null, path: '/'});
			}
			function cookieDel(index) {
				$.cookie('submenuMark-' + index, null, {expires: null, path: '/'});
			}
			
$(function() {
	
	$('a[rel^=prettyPhoto]').prettyPhoto({
		animationSpeed:'slow',
		theme:'facebook',
		opacity: 0.50
	});

    $(".video-container").fitVids();
	
});

