// jQuery Functions
$(document).ready(function() {
	$("#header .nav li a.selected").parent().append('<span></span>');

	$(".iconblock .item a").hover(function() {
		var src = $(this).children("img").attr('src');
		var src_parts = src.split('.')
		$(this).children("img").attr('src', src_parts[0] + "_over." + src_parts[1]);
	}, function() {
		var src = $(this).children("img").attr('src');
		var src_parts = src.split('_over')
		$(this).children("img").attr('src', src_parts[0] + src_parts[1]);
	});
	
	/**
	 * Delete confirmation
	 */
	$("a.delete-record").click(function() {
		var answer = confirm("Are you sure you wish to delete this record?");
		
		if (!answer) {
			return false;
		}
	});
	
	/**
	 * Pagination Limit Update
	 */
	$("select.pagination_limit").change(function() {
		$(this).parents('form').submit();
	});
	
	/**
	 * New Window
	 */
	$("a.new-window").click(function() {
		window.open(this.href);
		return false;
	});

	/**
	 * Header Postcode
	 */
	$("#header-info input.text").click(function() {
		if ($(this).val() == 'Postcode') {
			$(this).val('');
		}
	});
	$("#header-info input.text").blur(function() {
		if ($(this).val() == '') {
			$(this).val('Postcode');
		}
	});

	// Commercials Videos Fancy box
	$("a.fancybox-video").click(function() {
		$.fancybox({
			'padding' : 0,
			'autoScale' : false,
			'title' : this.title,
			'width' : 680,
			'height' : 495,
			'href' : this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type' : 'swf',
			'swf' : {
				'wmode' : 'transparent',
				'allowfullscreen' : 'true'
			}
		});
		return false;
	});

});
