jQuery(document).ready(function($){

	$('.imgbox, .imgbox-last').hover(function() {
		$(this).find('.location').addClass('locationHover');
		$(this).find('.date').addClass('dateHover');
		$(this).find('.author').addClass('authorHover');
	},function(){
		$(this).find('.location').removeClass('locationHover');
		$(this).find('.date').removeClass('dateHover');
		$(this).find('.author').removeClass('authorHover');
	});
	
	
	$('.more').click(function() {
		var p = $(this).position();
		var divId = $(this).attr('divId');
		var title = $(this).attr('title');
		var $dialog = $('<div></div>').html($("#" + divId).html());
		
		$dialog.dialog({
			autoOpen: false,
			title: title,
			position: [p.left+75,p.top],
	        resizable: false,
	        draggable: false,
	        width: 190,
	        height: 300,
	        minHeight:50,
	        maxHeight:300
		});
			
		$dialog.dialog('open');

		return false;
	});
	
	
	if($('.ft-aino-images img').size()<2){
		$('.ft-aino-images').galleria({
			show_counter: false,
			thumbnails: false,
			show_imagenav: false
		})
	}else {
		$('.ft-aino-images').galleria({
			show_counter: false,
			thumbnails: false
		})
	}
          
	$('#single .gallery-item a').each(function(){
		var url = (($(this).attr('href')));
		var ext = url.slice(url.length-4,url.length)
		if(ext =='.jpg'||ext =='.gif'||ext =='.bmp'||ext =='.png'||ext =='jpeg')
		$(this).attr('rel','fancy_image')
	})

	$("a[rel=fancy_image]").fancybox({
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'titleShow'	: false,
		'overlayOpacity'	: '1',
		'overlayColor'	: '#000',
		'onComplete'	: function(){ $('#container, #topnav-container').animate({'opacity':1},0); $('embed').hide()},
		'onClosed'	: function(){  $('#container, #topnav-container').animate({'opacity':0.8},0); $('embed').show()}
	});

	/*FIRST IMAGE ANIMATION*/
	$('.imgbox .mini, .imgbox-last .mini, .imgbox .default_image, .imgbox-last .default_image').hover(function(){
	    $(this).stop().animate({opacity: 1},150)
	},function(){
	    $(this).stop().animate({opacity: 0.8})
	})
	
	/*RESIZE SINGLE IMAGES */
	$widget_size = 260;
	$max_width=693;
	          
	Xpos = ($('.post').length>0)?$('.post').offset():0;
	$( ".post img" ).load(
		function(){
			$width=$(this).attr("width");
			if($width>$max_width){
				$(this).attr("width",$max_width-5)
				.removeAttr("height");
			}
		}  
	);
	$( ".post img" ).each(
		function(){
			$width=$(this).attr("width");
				if($width>$max_width){
					$(this).attr("width",$max_width-5)
					.removeAttr("height")
				}
		}
	)
	$('img.ps_featured').each(
		function(){
			var $max_width=910;
			$width=$(this).attr("width");
			if($width>$max_width){
				$(this).attr("width",$max_width)
				.removeAttr("height")
			}
			Xpos = $('.post').offset();
		}
	)
	$('img.ps_featured').load( //chrome
		function(){
			var $max_width=910;
			$width=$(this).attr("width");
			if($width>$max_width){
				$(this).attr("width",$max_width)
				.removeAttr("height")
			}
			Xpos = $('.post').offset();  
		}
	)
	/*smooth scrolling to top */
	$("a[href='#top']").click(function() {
				$("html,body").animate({ scrollTop: 0 }, 400);
				return false;
	});

	$("a[href='#to_content']").click(function() {
				$("html,body").animate({ scrollTop: Xpos.top }, 400);
				return false;
	});

	/* HEADER MENU */
	$(".topnav ul.sub-menu, .topnav ul.children").hide();
	$(".topnav li ul.children").css({'margin-left':0});
	$(".topnav li").hover(function(){
		var $li=$(this);
		var offset = $(this).offset();       
		$(this).children(".topnav .sub-menu,.topnav .children").css({'top':function(){
            if($li.parent().is('.sub-menu, .children')){
				return $li.index()*($li.height());      
			}else{
				return offset.top+$li.height();
			}
		},'left':function(){
   			if($li.parent().is('.topnav .sub-menu,.topnav  .children')){
       			return $li.width()+4;
   			}else{
       			return offset.left;
   			}
		},'min-width':$li.width()+10}).fadeIn()
	},function(){
		$(this).children(".topnav .sub-menu,.topnav .children").hide()
	})

	$('.topnav li').each(function(){  
		if ( $(this).children('.children, .sub-menu').size() > 0 && $(this).parent('.children, .sub-menu').size()==0 ) { // in horizontal menu
			$(this).addClass('arrow-down')
		}
		if ( $(this).children('.children, .sub-menu').size() > 0 && $(this).parent('.children, .sub-menu').size()>0 ) { // in submenus
			$(this).addClass('arrow-next')
		}
	})
	
	$('#checkoutLink').click(function(){
		window.location = "/print/addToShoppingCart?id=" + $("#printId").val() + "&quantity="+$("#qtyMainItems").val();
	})
	
});

