// remap jQuery to $
(function($){})(window.jQuery);



///////// HIGHLIGHT ACTIVE LINKS depending on page URL location /////////
var loc = $(location).attr('href').split('/').slice(-1);
var locPhpPage = $(location).attr('href').split("?")[0].split("/").slice(-1); //// extract file name.extension from the complex php url

$(".inner_nav, .nav_links").find("a[href='"+locPhpPage+"']").each(function(){
	$(this).addClass("curr");
})
$(".inner_nav, .nav_links").find("a[href='"+loc+"']").each(function(){
	$(this).addClass("curr");
})
///// articles list ('All Arcticles' class 'curr') FIX /////
if( $('.articles_list').find('.curr').length > 1 ){
	$('.articles_list li:eq(0)').find('a').removeClass('curr');
}



// DISABLE TEXT SELECTION 1
(function($){

$.fn.disableSelection = function() {
    return this.each(function() {           
        $(this).attr('unselectable', 'on')
               .css({
					'-webkit-user-select': 'none',
					'-khtml-user-select': 'none',
					'-moz-user-select': 'none',
					'-ms-user-select': 'none',
					'-o-user-select': 'none',
					'user-select': 'none'
               })
               .each(function() {
                   this.onselectstart = function() { return false; };
               });
    });
};

})(jQuery);

$(function(){

	// DISABLE TEXT SELECTION 2
	$('.cont_middle').disableSelection();



	// DISABLE RIGHT CLICK!
	$('.cont_middle').bind("contextmenu",function(e){
		return false;
	}); 
	//
});



$(function(){

///// ADD AN ARROW WHERE .curr EXIST (do design an arrow before the .curr link!) /////
$('.inner_nav').prepend('<div id="menu_arrow"></div>');
var mArrowH = $('#menu_arrow').height(); // get arrow height to position it well!
var currLinkPos = $('.inner_nav').find('a.curr').position().top;
$('#menu_arrow').css({top: currLinkPos-(mArrowH/3)+'px'});

});



// trigger when page is ready 
$(window).load(function (){
	var contH = 0;
		$('.cont').each(function(){
	  if( $(this).height() >= contH ){
		contH = $(this).height();
	  }
	});
	$('.cont').height(contH);
	
	// SET FOOTER BOX HEIGHT
	var boxH = 0;
		$('.box').each(function(){
	  if( $(this).height() >= boxH ){
		boxH = $(this).height();
	  }
	});
	$('.box').height(boxH);	
});




// CLONE IMAGE TITLE TO SPAN element underneath the image
$('.menu_left img[title]').each(function(){
	var thisImgWidth = $(this).width();
	var thisImgTitle = $(this).attr('title');
	$(this).after('<span class="description" style="width'+thisImgWidth+'px"></span>');
	$(this).next('.description').text(thisImgTitle);
});





// CLONE NAV LINKS TO FOOTER
$('.nav_links').clone().prependTo('#footer').wrap('<div class="box" />');




$(function(){

	// CLONE INNER NAVIGATION LINKS TO BOTTOM
	$('.inner_nav ul').clone().prependTo('.inner_nav_bottom');
	$('.inner_nav_bottom ul').find('hr').remove();
	$('.inner_nav_bottom li').after('&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;');

});




	// REMOVE BORDER FROM LAST FOOTER BOX
	$('#footer .box').eq(-1).css({background:'none'});

	// video lightbox
	$('.video_popup').height( $(document).height() );
	// GET WINDOW SCROLLtop OFFSET
	var winScrT;
	$(window).scroll(function(){
		winScrT = $(window).scrollTop();
	});
	$.getDocHeight = function(){
		var D = document;
		return Math.max(Math.max(D.body.scrollHeight, D.documentElement.scrollHeight), Math.max(D.body.offsetHeight, D.documentElement.offsetHeight), Math.max(D.body.clientHeight, D.documentElement.clientHeight));
	};
	$('.play_dubrovnik').click(function(){

		$('.video_popup').height($.getDocHeight);
		
		$('#popup').css({
			top: (winScrT+15)+'px'
		});

		$('.video_popup').fadeTo(0,0).css({
			marginLeft:'0px'
		}).fadeTo(600,1);
	});

	$('.popup_close, .video_popup').click(function(){
		$('.video_popup').fadeTo(600,0,function(){
			$('.video_popup').hide();
		});
	}); 

	
	
	
	
	
	///////// LOGO MARQUEE TEXT SCROLLER ///////////

	$('.scrollingtext').bind('marquee', function() {
		var sct = $(this);
		var tw = sct.width();
		var ww = sct.parent().width();
		sct.css({left: ww+'px'});
		sct.animate({
			left: -tw
		}, 20000, 'linear', function() {
			sct.trigger('marquee');
		});
	}).trigger('marquee');

	
	
	
	
	
	//////// BACK TO TOP button //////////////////

	// SLIDE UP
	function scroll(){
	var headerPos = $('#header').position().top;
	var scrolled = $('#scroll_top').offset().top;
	var speed = scrolled;
	$('html, body').animate({ scrollTop: headerPos }, speed);
	}
	$('#scroll_top').click(function(){
	scroll();
	}); 

	
	
	
	
	
	// make main page 'read more' images clickable //////////////////////////
	$('.cont_bottom').click(function(){
		window.location = $(this).children('a').attr('href');
		return false;
	}); 


	
	
	
	
//  PREVIEW_ARTICLES modifications! //	

	$('.article_preview img').remove(); // remove images from ('read_more') articles
	/* executed by PHP using substr - no need to use this lines
	$('.article_preview').each(function(){
		$(this).html($(this).html().substr(0, 375)+'...'); // CROP TEXTS
	});
	*/	
	/*
	$('.articles_list ul li a').each(function(){ // replace character '-' with ' ' (space) // '-' is generated by Pulse!
		$(this).text($(this).text().replace('-',' ')); // info: first letter in a sentence is capitalized with php using 'ucfirst'
	});
*/
	
	
	
	
///////////////////////////////////////////////////
	
/* optional triggers

$(window).load(function() {
	
});

$(window).resize(function() {
	
});

*/
