var stopVideoID = 0;

function getVideoRef(){
	if(navigator.appName.indexOf("Microsoft") != -1){
		return window['mercator_video_v' + stopVideoID];
	}
	else{
		return document['mercator_video_v' + stopVideoID];
	}
}

function stopVideoNow(){
	getVideoRef().stopVideo();
}

(function ($) {$(function () {
	if ($('html').hasClass('ie'))
	{
		$('.content table tr:even').addClass('even');
	}
	
	$('.external-services li').not('.external-services li.extra').hover(function ()
	{
		$(this).css('cursor','pointer');
/*		$(this).children('h3').addClass('hover');	*/
	},function () {
/*		$(this).children('h3').removeClass('hover');*/
	}
	).click(function ()
	{
		var link = $(this).find('h3 a').attr('href');
		var blank = $(this).find('h3 a').hasClass('external');
		if (blank)
		{
			window.open(link);
		}
		else
		{
			location.href = link;
		}
		
		return false;
	});

	$('.dropdown a').click(function (e){
		var button = $(this);
		if (!button.parent().parent().parent().hasClass('langs'))
		{
			e.preventDefault();
		}

		button.toggleClass('open');
		button.next('ul').toggle().parent('.dropdown').css('z-index',1);

		$('.dropdown ul').not(button.next('ul')).hide().prev('a').removeClass('open').parent('div').css('z-index',0);
		
		if (!button.parent().parent().parent().hasClass('langs'))
		{
			e.stopPropagation();
		}
	});
	
	$('.dropdown ul li a').click(function (e)
	{
		location.href = $(this).attr('href');
	});
	
	$('body').click(function () {$('.dropdown ul').hide().prev('a').removeClass('open');}); //cleara vse ob kliku na body
		
	var domain = top.location.href.match(/(\/\/.*?)\/+/i)[1];
	$('a.external').live('click', (function(e){e.preventDefault();window.open($(this).attr('href'));}));
	$("a[href^='http']:not(a[href^='http:" + domain + "'])").addClass('external');
	
	$('.gallery, .gallery-cards').each(function ()
	{
		$('a', $(this)).lightBox({
			fixedNavigation: true,
			overlayBgColor: '#000',
			overlayOpacity: 0.9,
			imageBlank: '/Static/images/lightbox/lightbox-blank.gif',
			imageLoading: '/Static/images/lightbox/lightbox-loading.gif',
			imageBtnClose: '/Static/images/lightbox/lightbox-closelabel.gif',
			imageBtnPrev: '/Static/images/lightbox/lightbox-btn-prev.gif',
			imageBtnNext: '/Static/images/lightbox/lightbox-btn-next.gif',
			txtImage: 'Slika',
			txtOf: 'od',
			containerBorderSize: '0',
			containerResizeSpeed: 200
		});
	});
	
	function showDropdown(element)
	{
		element.parent('div').addClass('open').css('z-index',2);
		element.next('ul').slideDown(300);
	}
	
	function hideDropdown(element)
	{
		element.parent('div').removeClass('open').css('z-index',0);
		element.next('ul').slideUp(300);
	}
	
	$('.dropdown a.trigger').toggle(function (e)	{
		//$('div.dropdown').css('z-index',0);
		e.preventDefault();
		showDropdown($(this));
		hideDropdown($('div.dropdown a.trigger').not(this));
	},
	function (e) {
		//$('div.dropdown').css('z-index',0);
		e.preventDefault();
		hideDropdown($(this));
	});

	var stevilo = $('.level-2').length;
	if (stevilo == 1) {
		$('ul.resources ').css('background','none');
	}

	function hasHash() {
		var urlStart = location.href.lastIndexOf('#/');
		var url = location.href.substr(urlStart + 2);
		if (urlStart > 1) {
			$('div.show').removeClass('show').removeAttr('style');
			$('div#' + url).hide().addClass('show').fadeIn(1000);
			$('ul.menu-alt>li').removeClass('selected');
			Cufon.refresh();
		} else {
			$('div.show').hide().fadeIn(1000);
		}
		$('ul.menu-alt>li>a').each(function(){
			var t = $(this);
			if (t.attr('href').substr(2) == url) {
				t.parent('li').addClass('selected');
				Cufon.refresh();
			}
		});
		
	}

	if ($('ul.menu-alt').length > 0) {
		SWFAddress.onChange = function(){hasHash()};
	}

	flash = $.browser.msie ? 'object' : 'embed';
	$('ul.menu-alt>li>a').click(function(e){
		e.stopPropagation();
		
		var t = $(this);
		var pID = t.parent('li').parent('ul').find('li.selected a');
		if($('div#'+ pID.attr('href').substr(2) + ' div.flash-replace-video ' + flash).length > 0) {
			stopVideoID = pID.attr('id').substr(1);
		}
		else {stopVideoID = 0};
		if (stopVideoID != 0) {stopVideoNow()};
		t.parent('li').parent('ul').find('li').removeClass('selected');
		t.parents('li').addClass('selected');
		Cufon.refresh();
	});


	if (('div#list>#stores').length > 1)
	{
		$('div#list>#stores>li').each(function()
		{
			$(this).addClass('off').append('<a href="#" class="on-off" />')
		});
		$('a.on-off').click(function(e)
		{
			e.preventDefault();
			var t = $(this);
			var $li = t.parent('li');
			var button = ($li.hasClass('on')) ? false : true;
			var slide = t.prev('div.description').find('div.show-more,div.serv');

			if (button)
			{
				$li.removeClass('off').addClass('on');
				slide.slideDown('fast');
				if($li.hasClass('isGroup')) {
					if(!t.prev('div.description').find('.storeGrouList').length) {
						var $groupPlaceholder = $('<div class="storeGrouList"></div>');
						t.prev('div.description').append($groupPlaceholder);
						$groupPlaceholder.load('ajaxStoreGroup.html?storeId=' + $li.attr('id').substring(2));
					} else {
						t.prev('div.description').find('.storeGrouList').show();
					}
						
				}
			}
			else
			{
				$li.removeClass('on').addClass('off');
				t.prev('div.description').find('.storeGrouList').hide();
				slide.slideUp('fast');
			}
		});
	}
	
	$('#vote_a').click(function (e) {
		$("#basic-modal-content").modal({
			overlayClose:true,
			opacity:20,
			onOpen: function (dialog) {
				dialog.overlay.fadeIn('fast', function () {
					dialog.data.hide();
					dialog.container.fadeIn('fast', function () {
						dialog.data.show();
					});
				});
		}});
	});
	
/*	$('#vote_a').click(function (e) {
		$('#basic-modal-content').modal({
				overlayClose:true
			});
		return false;
	});
*/
	
	$('#floors').tabs();
	$('#floors').tabs('select', '0');
	
	// return an array( 0 => (reference to the store in list, and reference to the circled number on the map), 1=> (the <li> element with the store's tooltip))  
	function findStore(vhodfunkcije){
		var myClass = vhodfunkcije.attr('class');
		var Classes = myClass.split(' ');
		return [$('.columns a.' + Classes[1] + ', .floor-list a.' + Classes[1]), $('.floor-list a.' + Classes[1]).parent()];
	};
	
	
	$('.floor-list a.icon, .columns a.desc')
	.click(function(e)
		{
			e.preventDefault();
		})
	.hover(function() 
		{
			var store = findStore($(this));
			store[0].toggleClass('hovered');
			store[1].mouseenter();
		}, function() {
			var store = findStore($(this));
			store[0].toggleClass('hovered');
			store[1].mouseleave();
		});
	

	
	$('.store-detail li.store').hover(function ()
		{
			$(this).css('z-index', '100');
			$(this).children('.tooltip').show();

		},function () {
			$(this).css('z-index', '1');
			$(this).children('.tooltip').hide();
		}
	);
	
	
	$('.store-detail .tooltip').hover(function ()
		{
			$(this).show();

		},function () {
			$(this).hide();
		}
	);
	

})})(jQuery);




