/**
 * @author Marcin
 */

var single 	= $("meta[name=single]").attr('content');

$(document).ready(function() {
	$('a.spamemail').nospam();
	
	//support for contact form validation
	form_validation();
	validate_all();
	
	var dropdownmenuargs = {
		navItemSelector: 'li',
		dropdownSelector: 'ul',
		dropdownShowDelay: 100,
		dropdownHideDelay: 500
	};
	$('ul.topmenu').dropem(dropdownmenuargs);
 
	
	//support ajax comments diffrent on blog and on single
	if( single == 'yes' ) {
		ajax_single_add_comment()
	} else {
		ajax_add_comment()
	}
	
	//support for ipad menu
	ios_nav_menu();
		
	//styling for last menu items
	$('.tmenu li:last, .tmenu li li:last').addClass('last');
	$('#footer ul li:last a').addClass('last');
	
	//hp image rotator active
	$('#rotator .blogimages')
		.after('<div class="ssnav">')
		.cycle({
			fx:		'fade',
			speedIn: 2000,
			speedOut: 2000,
			speed: 3500,
			height:	'625px',
			pager:  '.ssnav',
			after: function(curr,next,opts) { onAfter(curr,next,opts); } 
		});
	$('#rotator .ssnav').click(function() { 
    	$('#rotator .blogimages').cycle('pause'); 
    });
	
	//supports for homepage text slider
	$('.hpcontent').hide();
	$('#hp').append('<div class="hpcontentsw"><a class="off"></a></div>')
	
	$('.hpcontentsw').hover(
		 function () {
    		$(this).addClass('hover');
 		},
  		function () {
    		$(this).removeClass('hover');
  		});
	$('.hpcontentsw').bind("click", function(){ 
		$this = $(this);
		$thisa = $this.find('a');
		if ($thisa.attr('class') == 'off') {
			$('.hpcontent').slideDown('slow');
			$thisa.attr('class', 'on');
		}
		else if ($thisa.attr('class') == 'on') {
			$('.hpcontent').slideUp('slow');
			$thisa.attr('class', 'off');
		}
	});
	$('.hpcontentsw').css('display', 'none');
	
	//disables context menu on blog images
	$('.post a:has(img):not( .post .post-featured-image a:has(img) ), .post img:not( .post .post-featured-image img )')
		.css('cursor', 'default')
		.click(function(){return false;})
		.bind('contextmenu', function(){return false;}
	);

	$('.blogimages img, .post-featured-image img').each(function(){
		$(this).attr('rel', $(this).attr('title'));
		$(this).removeAttr('title');
	})
	
	$('div.post_datetime').click(function(){
		$('.blogimages img, .post-featured-image img').each(function(){
			$(this).attr('title', $(this).attr('rel'));
		})
	})
	
});

onAfter = function(curr,next,opts) {
	var currentSlide = (opts.currSlide + 1) ;
	clicky.log('/#menu/hp/slide'+ currentSlide,'Slide watched: ' + currentSlide);
}


