$(document).ready(function() {
	$('input[type=text]').focus(function(){
		var currentVal = $(this).val();										// Read initial field value
		$(this).val('');														// Clear initial value

		$(this).blur(function(){
			var getNewVal = $(this).val();										// Read new input value
			if ( getNewVal == '' || getNewVal == ' ' ) {
				$(this).val(currentVal);										// Switch to initial value
			}
		});
	});

	// fix PNG for IE6
	DD_belatedPNG.fix('img');

	// cufon
	Cufon.replace('p#slogan, h1, #getViaJS h3, h2, #events-news ul li div h3, dt');

	// remove any borders on last LI element
	$("ul").not('#footer ul').each(function(){
		 $(this).children("li:last").css({borderRight:"0",borderBottom:"0",background:"none",paddingRight:"0",marginRight:"0"});
	});

	// apply jscollpane
	if ( $('.scroll-pane').length )
		$('.scroll-pane').jScrollPane({showArrows: true, scrollbarWidth: 9, arrowSize: 15});

	// remove margin on 5th li
	if ( $('#landing-listing ul').length ) {
		$('#landing-listing ul li:nth-child(5n)').addClass('last');
	}

	// remove margin on 4th li
	if ( $('#pview-desc ul').length ) {
		//$('.pview-landscape #pview-desc ul li:nth-child(4n)').addClass('last');
		//$('.pview-square #pview-desc ul li:nth-child(7n)').addClass('last');
		//$('.pview-portrait #pview-desc ul li:nth-child(9n)').addClass('last');
	}

	// scroller for gallery
	var scrollerStep = 9;
	if ( $("#scrollme").length ) {
		var indexLi = $("#scrollme ul li").length;
		$("a#prev").fadeOut();
		if(indexLi <= scrollerStep)
			$("a#next").fadeOut();
		$('#scrollme').serialScroll({
			items:'li',
			prev:'a#prev',
			next:'a#next',
			axis:'x',
			start:0,
			duration:300,
			force:true,
			cycle:false,
			exclude:'8',
			step:scrollerStep,
			onBefore:function(button, e, elem, $pane, $items, pos){
				if ( $items == 0 ) { // reached left margin
					$("a#prev").fadeOut();
				}

				if ( $items == indexLi-scrollerStep ) { // reached right margin
					$("a#next").fadeOut();
				}
			}
		});

		$("a#prev").click(function(){
			$("a#next:hidden").fadeIn();
			$('#scrollme').trigger('prev');
		});
		$("a#next").click(function(){
			$("a#prev:hidden").fadeIn();
			$('#scrollme').trigger('next');
		});
	}

	$('#scrollme a, #pview-desc ul li a').click(function(){
		return false;
	});

	// tick all for contact form
	$("#contact-form a.tick-all").click(function(){
		$(this).parent().find("input").each(function(){
			this.checked = 'checked';
		});
		return false;
	});

	if ( $(".datepicker").length ) {
		$(".datepicker").datepicker({ dateFormat: 'dd/mm/yy' });
	}

});

jQuery.fn.log = function (msg) {
  console.log("%s: %o", msg, this);
  return this;
};
