/* custom.js */

/*============= SLIDESHOW ======================*/

	function slideshow()
	{
		var stop = false;
		var links = [];
		var index = 0;
	
		function slideshow()
		{
			if( stop ) return;
			
			slide_next();
			setTimeout(slideshow, 4000);
		}
		
		function stop_slideshow()
		{
			stop = true;
		}
		
		function start_slideshow()
		{
			stop = false;
			setTimeout(slideshow, 4000);
		}
		
		function slide_next()
		{
			var nextIndex = index+1;
			if( nextIndex >= links.length ) nextIndex = 0;
			
			var current = links[index];
			var next = links[nextIndex];
			
			var currentImageId = current.hash;
			var nextImageId = next.hash;
			
			$(current).removeClass('selected');
			$(next).addClass('selected');
			
			$(currentImageId).stop(false, true).fadeOut(1000);
			$(nextImageId).stop(false, true).fadeIn(1000);
			
			$(currentImageId+'-info').hide();
			$(nextImageId+'-info').show();
			
			index = nextIndex;
		}
		
		function slideshow_click( element )
		{
			stop_slideshow();
			
			var current = links[index];
			var next = element;
			
			if( current == next ) return;
			
			var currentImageId = current.hash;
			var nextImageId = next.hash;
			
			$(current).removeClass('selected');
			$(next).addClass('selected');
			
			$(currentImageId).fadeOut(1000);
			$(nextImageId).fadeIn(1000);
			
			$(currentImageId+'-info').hide();
			$(nextImageId+'-info').show();
			
			for( var i = 0; i < links.length; i++)
			{
				if(links[i] != element) continue;
				index = i;
				break;
			}
		}
		
		this.stop = stop_slideshow;
		
		this.start = start_slideshow;
		
		this.init = function(){
			
			links = $('#slideshow .menu-item a');
			
			$('#slideshow .menu-item a').click(function(event){
				event.preventDefault();
				slideshow_click( this );
			});
			
			$('#slideshow .image').hover(function(){
				$('#slideshow .image-info').stop(false, true).slideToggle();
			});
			
			start_slideshow();
		};
	}


/* ============= BROWSER SUPPORT ============== */

	function browser_support()
	{
		if( !is_browser_supported() )
		{
			html = ''+
					'<div style="padding: 20px">'+
					'<h3 style="color:red">Warning</h3>'+
					'<p style="font-size: 14px">'+
						'You are using <strong>MS Internet Explorer</strong> version <strong>less than 9</strong> or <strong>Mozilla Firefox</strong> version <strong>less than 3.6</strong>'+
						' which do not support advanced technologies used to build this site. Because of this you may not'+
						' see this site as it was originaly intended. <br /><br />'+
						'For full user experience please download latest version of your favourite browser. Links are'+
						' located bellow this text. <br /><br />'+
						'If you do not know which browser to choose, I recommend Google Chrome or Firefox.'+
					'</p>'+
					'<p style="font-size: 14px">'+
						'<a href="http://www.google.com/chrome">Google Chrome</a>&nbsp;&nbsp;'+
						'<a href="http://www.mozilla.com/">Firefox</a>&nbsp;&nbsp;'+
						'<a href="http://www.microsoft.com/windows/internet-explorer/default.aspx">Internet Explorer</a>&nbsp;&nbsp;'+
						'<a href="http://www.opera.com/">Opera</a>&nbsp;&nbsp;'+
						'<a href="http://www.apple.com/safari/">Safari</a>&nbsp;&nbsp;'+
					'</p>'+
					'<p style="font-size: 14px">'+
						'Best regards,<br /><strong>Miroslav</strong>'+
					'</p>'+
					'</div>';
			$('#browser-warning').html(html);
			$('#browser-trigger').trigger('click');
		}
	}
	
	function is_browser_supported()
	{
		var ie = parseInt($.browser.version) <= 8 && $.browser.msie;
		var moz = $.browser.mozilla && parseInt( $.browser.version.slice(0,1) ) <=1	&& $.browser.version != "1.9.2";
		
		return !(ie || moz);
	}
	
	
/* ============== JQUERY ON READY ===================*/

	$(document).ready(function(){
		fakSlideshow = new slideshow();
		fakSlideshow.init();
		
		$('.sidebar-image-holder').hover(function(){
			$(this).find('.title').fadeToggle();
		});
		
		$('.majesticLogo-menu').hover(function(){
			$(this).find('.submenu').first().fadeToggle();
		});
	
	});

