// JavaScript Document


$(document).ready(function() {	

	if($(".admin_shortcut").length > 0){
		$(".admin_shortcut").fancybox({
			'overlayOpacity'    : .8,
			'overlayColor'      : '#8b0b21',
			'width'				: '90%',
			'height'			: '90%',
			'autoScale'     	: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe',
			'onClosed'        : function() {
				location.reload(true);
			}
		});	
	}

	/*
	INTRO	
	*/
	var intro = $('.intro');
	
	intro.click(function(){ 
		$(this).hide();
	})
	
	if(intro.length > 0){
		$('div img', intro).fadeIn(1500, function(){
			$(this).delay(1000).animate({
				'margin-left': -405
			}, 500, function(){
				$('div', intro).fadeOut(500, function(){
					$(intro).delay(10000).fadeOut(500)
				})
			})
		});
	}
	/* 
	HOME PAGE - Thumbs animation
	*/
	
	var hero = $('article.content ul.heroes li section a img');
	
	$(hero).live('mouseover', function(){
		
		$(this).parent().css('z-index','1000');
		
		$(this).stop(true, true).animate({
			width:120,
			height:120,
			left:-5,
			top:5	
		},	200).siblings('h1').stop(true, true).delay(200).slideDown(200).siblings('img.shadow').stop(true, true).animate({
				width:130,
				height:130,
				left:-10,
				top:0	
				}, 200);		
	})
	
	$(hero).live('mouseout', function(){
		
		$(this).stop(true, true).animate({
			width:110,
			height:110,
			left:0,
			top:10
		},	200).siblings('h1').stop(true, true).fadeOut(100, function(){
				$(this).parent().css('z-index','1');
			}).siblings('img.shadow').stop(true, true).animate({
				width:110,
				height:110,
				left:0,
				top:10	
				}, 200);		;
		
	})
	
	var showHide = false;
	$('li.sub').live('click', function(){
		
		if(!$(this).children('ul').is(':visible')){			
			$(this).children('ul').slideDown(300);
			$('li.sub ul, li.open ul').not($(this).children('ul')).slideUp(300);
			return false;
		}else{
			$(this).children('ul').slideUp(300)
		}
		//
		
	})
	
	/* 
	SHOW MORE BUTTON
	*/
	
	$('.one-hero .stories .show-more').live('click', function(){
		
		$(this).hide();
		$('.one-hero .stories .line').fadeIn(300);
		$('.one-hero .stories .more').slideDown(300);
		return false;
		
	})
	
	/* 
	HERO IMAGE GALLERY
	*/
	
	$(".slider").easySlider({
		prevId: 'prevBtn',
		nextId: 'nextBtn'
	});

	function placeImg(){
		
		if($('.gallery').length > 0){
			
			var obj = $('.gallery .slider ul li a.current');
			
			var src = obj.attr('href');
			var title = obj.attr('title');
			var id = obj.attr('id');
			
			if(src.indexOf(".f4v") != -1 || src.indexOf(".flv") != -1) {
						
				$('#flash').removeClass('displaynone');
				$('#place').addClass('displaynone');
				$('#zoom').addClass('displaynone');
				
				$("#player2").remove();
				$("object").remove();
				$('#flash').append('<a href="' + src + '" id="player2" style="display:block; width:325px; height:325px;"> </a>');   
				flowplayer("player2", 
					{src:"/www/swf/flowplayer-3.2.5-1.swf", wmode:"transparent", key: "#@81b23aae947d14e8e17"}, 
					{play: {replayLabel: 'pogledaj ponovo'},
					clip: {scaling: 'fit'},
					canvas:  { backgroundGradient: 'none',backgroundColor: '#000000'}
				});
				
			}else if(src.indexOf(".jpg") != -1 || src.indexOf(".jpeg") != -1 ){
				
				$('#flash').addClass('displaynone');
				$('#place').removeClass('displaynone');  
				$('#zoom').removeClass('displaynone');  
				$('#place').hide(); 
				
				$('#place').load(function () {
					$(this).fadeIn(500);
					$(this).attr('title', title);
				}).error(function () {
					// notify the user that the image could not be loaded
				}).attr('src', src).attr('rel', obj.attr('id'));
				
				$('.stories .story .award').hide();
				$('.stories .story .award#'+obj.attr('id')+'aw').show();
			
			}
		}
	}
	
	$('.slider ul li a').live('click', function(event){
		
		event.preventDefault();		
		var obj=$(this);

		$('.gallery .slider').find('a.current img').animate({opacity: 1 });
			$('.gallery .slider').find('a.current').removeClass('current');
			obj.addClass('current');
			placeImg ();
	});	
	
	
	/* 
	FAMOUS FADER
	*/
	
	var famousTmp = '0';
	$('.famous ul.famous-navigation li a').live('click', function(event){
		
		event.preventDefault();	
		
		famous = $(this).attr('href').split('-')[1];		
		if(famous != famousTmp) {
			
			$('.famous ul.famous-navigation li a').css('color','#FFF');
			$('.famous ul.famous-navigation li a.fam-' + famous).css('color','#CCC');
			
			$('.famous ul.famous-list li#famous-'+famousTmp).fadeOut(300, function(){
				//alert('.famous ul.famous-list li#famous-'+famousTmp)
				$('#famous-' + famous).fadeIn(100);
			})
			famousTmp = famous;
		}
	});
	
	/*
	FANCYBOX
	*/
	
	$("a[rel=hero-gallery]").fancybox({
		'overlayOpacity'	: 1,
		'overlayColor' 		: '#8b0b21',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">(' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ') &nbsp; ' + title : '') + '</span>';
		}
	});
	
	$('#zoom a').live('click', function(){
		var imgID = $("#place").attr('rel');
		$("#"+imgID+"hr").focus();
		$("#"+imgID+"hr").click();
	});
	
	/*
	 FOOTER POSITION
	 */
	 
	var viewportHeight = $(window).height();
	var articleHeight  = $('article.content').height()
	
	if(viewportHeight > (articleHeight + 170)){
		$('footer p').css({'position':'fixed','bottom':'0px'});
	}
	
	


/* END DOCUMENT READY*/	
});

/*------------------------------------------------------------------------------------------------------------------------------------*/
/* jquery.cookie.js */
/*jslint browser: true */ /*global jQuery: true */

/**
 * jQuery Cookie plugin
 *
 * Copyright (c) 2010 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

// TODO JsDoc

/**
 * Create a cookie with the given key and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 
 * @param String key The key of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given key.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String key The key of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function (key, value, options) {

    // key and value given, set cookie...
    if (arguments.length > 1 && (value === null || typeof value !== "object")) {
        options = jQuery.extend({}, options);

        if (value === null) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? String(value) : encodeURIComponent(String(value)),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};





































