$(document).ready(function() {
	// Cufon
	//Cufon.replace('.cufon-replace');

	// Slimbox
	if ($('a[rev^="lightbox"]').length > 0) {
		$('a[rev^="lightbox"]').colorbox();
	}

	// External links
	$('a.external').click(function() {
		window.open($(this).attr('href'), 'blank');

		return false;
	});

	// Back links
	$('a.back').click(function() {
		history.go(-1);

		return false;
	});

	// Anchor link base tag workaround.
	$('a[href^=#]').click(function(e) {
		e.preventDefault();
		var anchor = $(this).attr('href').replace(/\#/i, '');
		document.location.hash = anchor;
	});

	// Clean junk on form submit
	$('form').submit(function() {
		$(this).find('input[title], textarea[title]').each(function() {
			if ($(this).attr('title') == $(this).attr('value')) $(this).attr('value', '');
		});
	});

	// Link click confirm
	if ($('a.confirm.external').length > 0) {
		$('a.confirm.external').click(function() {
			var url = $(this).attr('href');

			$('<div>You are about to open a link to ' + url + ', continue?</div>').dialog({
				title: 'External link',
				modal: true,
				buttons: {
					Yes: function(){
						$(this).dialog('close');
						window.open(url, 'blank');
					},
					No: function(){
						$(this).dialog('close');
					}
				}
			});

			return false;
		});
	}

	// Copy input title content into value only if value is empty (allows for fields to be pre-populated e.g. from php)
	$('input[title], textarea[title]').each(function() {
		var el = $(this);

		function sticky() {
			if (el.attr('value').length == 0) {
				el.attr('value', el.attr('title'));
			}
		}

		// reset on mouse out
		$(this).blur(function() {
			sticky();
		});

		// clear on mouse in
		$(this).focus(function() {
			if (el.attr('title') == el.attr('value')) {
				el.attr('value', '');
			}
		});

		// initialise
		sticky();
	});

// Not sure what this is?
$(function() {

			$('.rtbgphoto').hover(function(){
				$(this).find('.caption').animate({top:'0px'},{queue:false,duration:500});
			}, function(){
				$(this).find('.caption').animate({top:'-138px'},{queue:false,duration:500});
			});
		});


 $('#top-nav > ul > li').hover(function(){
		$(this).find('ul:first').slideDown(400).css({visibility: 'visible',display: 'none'}).stop(false,true);

													},
		function(){
		$(this).find('ul:first').slideUp(100).stop(false,true);//.css({visibility: 'hidden'});

		});



 $('#top-nav ul > li > ul').hover(function(){
		$(this).prev('a').addClass('jqtop'); // use prev for <ul> bcoz after <a> tag , <ul> has start tag and end tag
		},
		function(){
		$(this).prev('a').removeClass('jqtop');
		});



 $('#cont-text input[type="text"], textarea')
       .focus(function(){ //click
		if($(this).val() == this.defaultValue ){ // if($(this).val() !== ''
			    $(this).val('');
				             }
	$(this).addClass('jq-active');
			})
      .blur(function(){
		if($(this).val() == ''){
			$(this).val(this.defaultValue);
			}
	$(this).removeClass('jq-active');
	});
});
