// JavaScript Document

function preloadImages(pathsArray) {
    $(pathsArray).each(function(){
        $('<img />')[0].src = this;
    });
}

$(function(){ 
	$('.formulate').eFormulate();
	
	// Open external and document links in new window
	$('a[href*=www],a[href*=http],a[href*=pdf]').not('a[href*='+location.hostname+']').attr('target','_blank');
	
	// Setup simple page markers
	var bodyID =  $('body').attr('id');
	$('#site_nav a').each(function(){
		var hrefVal = $(this).attr('href');
		if(hrefVal.search(bodyID) != -1 || (bodyID == "home" && hrefVal == "/")) $(this).addClass('marker');
	});
	
	// Setup clickable block elements [extending a link]
	$('.click_block').css({cursor:'pointer'}).click(function(e){ e.preventDefault(); var first_link = $(this).find('a:first'); window.location = first_link.attr('href'); });
	
	// Setup animation for edition tiles
	$('.edition_tile').css({position:'relative'}).hover(function(){ $(this).stop(true,false).animate({top:-5},100); },function(){ $(this).animate({top:0},300); });
	
	// Article toolbar
	$('header .toolbar').not('#cart_nav .toolbar').append('<div class="nav_marker bg_<?php echo $edition_color; ?>"><div class="bg_blk20"></div></div>');
	$('.nav_marker').css({opacity:0}).show();
	$('.toolbar a').not('.drop_menu a').hover(
		function(){ $dposition = $(this).position(); $('.nav_marker,.nav_marker div').height($(this).outerHeight()); $('.nav_marker').stop(true,false).animate({opacity:1,width:$(this).outerWidth()+'px',left:$dposition.left+'px'},300); }, 
		function(){ $('.nav_marker').animate({opacity:0},400); }
	);	

});

$(window).load(function(){ 
	// Edition menu
	$('#aside_content nav a').eMenu({axis:'x',place:'left,top'});
	
	// Select edition menu
	$('#site_top nav a').eMenu({matchWidth:1});
});
