/*
		HASH funkcije, recimo:
			// kod otvaranja, zapamti url
			cbox_tempurl=document.location.hash;
			// kod zatvaranja, vrati url
			removeHash();
			// kod promjene slike, promijeni url #anthotypeID
			var $element=$.colorbox.element();
			changeUrl("#my"+$element.attr("id"));
			// kod startanja stranice provjeri jel ima hash
			// -- ako je postavljen Hash, pokreni sliku	
			hash=resolveHash();
			if(hash.substr(0,11)=="myanthotype"){
				startImage=hash.substr(2);
				$("#"+startImage).eq(0).click();
			}

*/
/*
function changeUrl(hash){
 document.location.hash=hash; 
	return false;
}
function removeHash () { 
    if ("pushState" in history)
        history.pushState("", document.title, window.location.pathname);
    else
        window.location.hash = "";
}
function resolveHash(){
	hasher = document.location.hash;
	hasher = hasher.replace(/^.*#/, '');
	return hasher;
}
*/
(function($){
     $.fn.extend({
          center: function (options) {
               var options =  $.extend({ // Default values
                    inside:window, // element, center into window
                    transition: 0, // millisecond, transition time
                    minX:0, // pixel, minimum left element value
                    minY:0, // pixel, minimum top element value
                    withScrolling:true, // booleen, take care of the scrollbar (scrollTop)
                    vertical:true, // booleen, center vertical
                    horizontal:true // booleen, center horizontal
               }, options);
               return this.each(function() {
                    var props = {position:'absolute'};
                    if (options.vertical) {
                         var top = ($(options.inside).height() - $(this).outerHeight()) / 2;
                         if (options.withScrolling) top += $(options.inside).scrollTop() || 0;
                         top = (top > options.minY ? top : options.minY);
                         $.extend(props, {top: top+'px'});
                    }
                    if (options.horizontal) {
                          var left = ($(options.inside).width() - $(this).outerWidth()) / 2;
                          if (options.withScrolling) left += $(options.inside).scrollLeft() || 0;
                          left = (left > options.minX ? left : options.minX);
                          $.extend(props, {left: left+'px'});
                    }
                    if (options.transition > 0) $(this).animate(props, options.transition);
                    else $(this).css(props);
                    return $(this);
               });
          }
     });
})(jQuery);


$(document).ready(function(){

	// ==========================================
	// AJAX activity ----------------------------
	$.ajaxSetup ({
	// Disable caching of AJAX responses
	cache: false
	});
	var loadingIndicator=$("<div>").html("<img src='/inc/css/gfx/nowLoading.gif' title='loading...' width='32' height='32'/>").css({'z-index':'1000','background':'#121212','border-top':'1px solid #000', 'border-bottom':'1px solid #000','padding-top':'32px', 'width':'100%', 'height':'68px'}).show();
	var loadingIndicatorContainer=$("<div>").css({'z-index':'999', 'position':'fixed', 'opacity':'.95', 'width':'100%', 'height':'100%', 'top':'0px', 'left':'0px' }).hide();
	loadingIndicatorContainer.prepend(loadingIndicator);
	$("html").prepend(loadingIndicatorContainer);
	loadingIndicatorContainer.bind("ajaxStart",
							function(){
								var top = ($(window).height() - 100) / 2;
								top +='px';	
								$(this).children("div:first").css({'position':'absolute', 'top':top}).show();
								$(this).show();
							}
						)
					.bind("ajaxStop", 
							function(){
								$(this).hide();
							}
						);
	
	// ==========================================
	// accordion --------------------------------
	$('.kategorija').accordion();
	
	// ==========================================
	// partners ---------------------------------
	$('#partnersLogo').unbind("click").click(function(){$('#popisContainerInner').slideToggle("fast");});
	
	// ==========================================
	// highlight sliku unutar itema -------------
	
	$('.itemImg').live({
		mouseenter: function(){
			$('li.kategorija.active  li.activeSlider .itemImg:not(.hidden), li.soloSlider .itemImg:not(.hidden)').stop().fadeTo("slow",.4);
			$(this).stop().fadeTo("slow",1);
		}, 
		mouseleave: function(){
			$('li.kategorija.active  li.activeSlider .itemImg:not(.hidden), li.soloSlider .itemImg:not(.hidden)').stop().fadeTo("fast",1);
		}
		//,
		//click: function(){
		//},
		});
		
	// ==========================================
	// activate gallery
	
	
	$("a[rel^='dvgal_']").prettyPhoto({
			opacity: 0.70, /* Value between 0 and 1 */
			default_width: 1000,
			default_height: 500,
			deeplinking: false,
			social_tools: false,
			horizontal_padding: 10, /* The padding on each side of the picture */
			theme: 'light_square2' // / dark_rounded / light_square / dark_square / facebook */
			
	});
	
/*	$(".pager a[rel^='dvgal_']").prettyPhoto({
			opacity: 0.70,
			default_width: 1000,
			default_height: 500,
			deeplinking: false,
			social_tools: false,
			horizontal_padding: 10, 
			theme: 'light_square2'			
	});
*/		
	
		
});

