var noFlash = false;
$(document).ready(function() {
	$('.pngFix').pngFix(); 
	$('a[target="_fancybox"]').fancybox({
		'titlePosition' : 'inside',
		'overlayColor'  : '#000',
		'overlayOpacity': '0.8'
	});
	$('a[target="_popup"]').fancybox({
		'type' : 'iframe',
		'overlayColor'  : '#000',
		'overlayOpacity': '0.8'
	});
	if($('.mainMedia .slider img').length>1) {
	    $('.mainMedia .slider').cycle({
			  fx: 'fade',
			  pager:  '.mainMedia-pager'
			 });
	}
	if(GetSwfVer()!=-1 && noFlash==false) {
		$('a.media').media({
				flashVersion:  '7'
		});
		$('.noFlash').hide();
	} else {
		$('a.media').hide();
	}
	// nav
	/*
	$('.nav li.on ul').animate({
		'left' : 0
	},800,'easeOutElastic');
	*/
	
	
	$('.nav li a ').hover(function (){
		$(this).stop().animate({
			backgroundPosition:"(0 0px)"
		},500,'easeOutBounce');
	},function() {
		if($(this).hasClass('on')) return false;
		$(this).stop().animate({
			backgroundPosition:"(0 -38px)"
		},600,'easeOutElastic');		
	});

	// newsbox
	$('.news-box .item').hover(function (){
		$(this).stop().animate({
			'top' : '-'+($(this).outerHeight()-28)+'px'
		},300,'easeOutExpo');
	},function() {
		$(this).stop().animate({
			'top' : '0px'
		},600,'easeOutElastic');		
	});
	
	// footer hack
	if($(document).height()<=$(window).height()+10) {
		$('.footer').height($(window).height()-$('.wrap').height()-197);
	}
	
	
	// form
	if($('.Ierror')[0]) {
		$('html, body').animate({scrollTop:$('.Ierror:eq(0)').offset().top}, 'fast',
			function() {
					$.fancybox(
					'<h2>'+$('h1').text()+'</h2><p style="color:red">'+$('legend').text()+'</p>',
					{
			        		'autoDimensions'	: false,
						'width'         		: 350,
						'height'        		: 'auto',
						'transitionIn'		: 'none',
						'transitionOut'		: 'none'
					}
					);	
			}
		
		);
			
	}
	function randomFromTo(from, to){
	       return Math.floor(Math.random() * (to - from + 1) + from);
	}
	// b - glas
	var anim = function(t) {
		if(randomFromTo(1,2)==1) {
			var c = $('<img src="img/struct/b/'+randomFromTo(1,3)+'.png"/>');
			$('.bb-glas').append(c);
			c.css({
				'left' : randomFromTo(30,200)+'px'
			});
			c.animate({
				'top'  : '-30px',
				'left' : randomFromTo(50,317)+'px'
			},randomFromTo(5000,20000));
		}
	};
	if(!$.browser.msie) {
		//window.setInterval(anim,1000);
	} 
});
jQuery(document).ready(function($) {
	if(!$('.gnav')[0]) return true;
	var gallery = $('.gnav').galleriffic({
		delay:                     2500,
		numThumbs:                 10,
		preloadAhead:              10,
		enableTopPager:            true,
		enableBottomPager:         false,
		maxPagesToShow:            7,
		imageContainerSel:         '.sgallery .slideshow',
		controlsContainerSel:      '.sgallery .controls',
		captionContainerSel:       '.sgallery .caption-container',
		loadingContainerSel:       '.sgallery .loader',
		renderSSControls:          true,
		renderNavControls:         true,
		playLinkText:              'play slideshow',
		pauseLinkText:             'pause slideshow',
		prevLinkText:              '&lsaquo; '+gL['prev'],
		nextLinkText:              gL['next']+' &rsaquo;',
		nextPageLinkText:          '&rsaquo;',
		prevPageLinkText:          '&lsaquo;',
		enableHistory:             true,
		autoStart:                 false,
		syncTransitions:           true,
		defaultTransitionDuration: 900,
		onSlideChange:             function(prevIndex, nextIndex) {
			// 'this' refers to the gallery, which is an extension of $('#thumbs')
			/*
			this.find('ul.thumbs').children()
				.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
				.eq(nextIndex).fadeTo('fast', 1.0);
			*/
		},
		onPageTransitionOut:       function(callback) {
			this.fadeTo('fast', 0.0, callback);
		},
		onPageTransitionIn:        function() {
			this.fadeTo('fast', 1.0);
		}
	});

	function pageload(hash) {
		if(hash) {
			$.galleriffic.gotoImage(hash);
		} else {
			gallery.gotoIndex(0);
		}
	}
	$.historyInit(pageload);
	$("a[rel='history']").live('click', function(e) {
		if (e.button != 0) return true;
		var hash = this.href;
		hash = hash.replace(/^.*#/, '');
		$.historyLoad(hash);
		return false;
	});
});



