
	// -- status dal je odvrćena početna animacija
	var status_animacije = 0;
	
	// -- varijable za hover efekt
	var curr_zindex = 0;
	var num = 0;
	// -- --
	
	// -- varijable za klik na kocku
	var cur_left = 0;
	var cur_top = 0;
	var cur_box = 0;
	var cur_width = 0;
	var cur_height = 0;
	
	var n_left = new Array();
	var n_top = new Array();
	
	n_left[1] = 0;
	n_top[1] = 0;
	n_left[2] = 245;
	n_top[2] = 0;
	n_left[3] = 490;
	n_top[3] = 0;
	n_left[4] = 718;
	n_top[4] = 0;
	n_left[5] = 65;
	n_top[5] = 57;
	n_left[6] = 344;
	n_top[6] = 49;
	n_left[7] = 587;
	n_top[7] = 57;
	// -- --
	
	$(document).ready(function(){
		
		// -- fancybox inicijalizacija
		$(".box_open").fancybox({
			'titleShow'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'autoDimensions'	: false,
			'padding'			: 6,
			'overlayColor'		: '#000000',
			'width'				: 400,
			'height'			: 400
		});
		
		$(".anketa_open").fancybox({
			'titleShow'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'autoDimensions'	: false,
			'padding'			: 6,
			'overlayColor'		: '#000000',
			'width'				: 300,
			'height'			: 300
		});
		// -- --
		
		
		// -- početna animacija
		$('.dcube, #logo, #title, #mago, #footer').css('display','none');
		
		$('#logo, #mago').animate({
			opacity: 'toggle',
			top: 0
		},300);
		
		$('#title').wait(400).animate({
			opacity: 'toggle',
			top: 0
		},700, 'easeOutBounce');
		
		$('#box6').animate({
			opacity: 'toggle'
		},2000, 'easeInQuart', function(){
			
			$('#box5, #box7').css({'left':'359px', 'top':'63px'});
			
			$('#box5').animate({
				opacity: 'toggle',
				left: 98,
				top: 80
			}, 500);
			
			$('#box7').animate({
				opacity: 'toggle',
				left: 605,
				top: 80
			}, 500, function(){
				$('#box1, #box2, #box3, #box4, #footer').fadeIn(500, function(){
					$('.box_sh').fadeIn(500);
					status_animacije = 1;
				});
			});
			
		});
		// -- --
		
		// -- hover efekt
		$('.dcube').hover(function(){
			
			if(status_animacije == 1)
			{
				clearTimeout(t);
				
				num = $(this).attr('rel');
				curr_zindex = $('#box'+num).css('z-index');
				//alert(curr_zindex);
				for(var i = 1; i <=7; i++)
				{
					if(i != num)
					{
						$('#box'+i).stop().animate({
							opacity: "0.2"
						}, 500);
					}
				}
				
				$('#box'+num).css('z-index', 10);
			}
			
		}, function(){
			
			if(status_animacije == 1)
			{
				//alert(curr_zindex);
				
				for(var i = 1; i <=7; i++)
				{
					$('#box'+i).stop().animate({
						opacity: "1"
					}, 500);
				}
				
				$(this).stop().animate({
					opacity: "0.5"
				}, 300, function(){
					$(this).animate({
						opacity: "1"
					}, 800);
				});
				
				
				$('#box'+num).css('z-index', curr_zindex);
				
				c = 0;
				start_to_count();
			}
		});
		// -- --
		
		$('.dcube').click(function(){
			
			if(status_animacije == 1)
			{
			
				if(cur_box != 0)
				{
					move_to_place();
				}
				
				if(cur_box != $(this).attr('rel'))
				{
					cur_box = $(this).attr('rel');
					var position = $('#box'+cur_box).position();
					cur_left = position.left;
					cur_top = position.top;
					cur_width = $('.box_img', this).width();
					cur_height = $('.box_img', this).height();
				}
				
				if(cur_box > 0 && cur_box <= 4)
				{
					new_height = 212;
					new_width = 188;
				}
				
				if(cur_box == 5 || cur_box == 7)
				{
					new_height = 260;
					new_width = 235;
				}
				
				if(cur_box == 6)
				{
					new_height = 234;
					new_width = 211;
				}
				
				$('#box'+cur_box+' .box_img').stop().animate({
					width: new_width+'px',
					height: new_height+'px',
					opacity: 1
				}, 500, function(){
					$('#box'+cur_box+' .box_txt').fadeIn(300);
				});
				
				$('#box'+cur_box).stop().animate({
					left: n_left[cur_box],
					top: n_top[cur_box],
					width: new_width+'px',
					height: new_height+'px'
				}, 500);
				
				$('#box_sh'+cur_box).css('display','none');
				
				return false;
			}
		});
		
		$("#footer_facebook").hover(function(){
			$("#footer_facebook_h",this).stop(true,true).fadeIn(900);
		},function(){
			$("#footer_facebook_h",this).stop(true,true).fadeOut(600);
		});
		
		$("#footer_anketa").hover(function(){
			$("#footer_anketa_h",this).stop(true,true).fadeIn(900);
		},function(){
			$("#footer_anketa_h",this).stop(true,true).fadeOut(600);
		});
		
	});
	
	function move_to_place()
	{
		//alert(cur_box);
		
		if(status_animacije == 1)
		{
			$('#box'+cur_box+' .box_txt').fadeOut(200);
			
			$('#box'+cur_box).stop().animate({
				left: cur_left,
				top: cur_top,
				width: cur_width,
				height: cur_height
			}, 500);
			
			$('#box'+cur_box+' .box_img').stop().animate({
				width: cur_width,
				height: cur_height
			}, 500);
			
			$('#box_sh'+cur_box).css('display','block');
		}
	}
	
	var c=0;
	var t;
	var started=0;
	function start_to_count()
	{
		c++;
		t = setTimeout("start_to_count()", 1000);
		//alert('b');
		
		if(c >= 3)
		{
			clearTimeout(t);
			
			var now_width = $('#box'+cur_box+' .box_img').width();
			//alert(cur_width);
			if(now_width > cur_width)
			{
				move_to_place();
				
				for(var i=1; i<=7; i++)
					$('#box'+i+' .box_txt').fadeOut(200);
			}
		}
	}
	
	
	$.fn.wait = function(time, type) {
        time = time || 1000;
        type = type || "fx";
        return this.queue(type, function() {
            var self = this;
            setTimeout(function() {
                $(self).dequeue();
            }, time);
        });
    };
	
	
	function goto_page(page)
	{
		window.location = page;
	}

