// Assests Document

// Loading Plugins
	$.lazy({ src: '/js/plugins/jquery.cycle.all.min.js', name: 'cycle' });
	$.lazy({ src: '/js/plugins/jquery.validationEngine.js', name: 'validationEngine' });
	$.lazy({ src: '/js/plugins/jquery.quickpaginate.packed.js', name: 'quickpaginate' });
	//$.lazy({ src: 'js/plugins/shadowbox3b/shadowbox.js', name: 'Shadowbox' });
// End of plugins

/**
 * @desc  EXTERNAL LINKS - traps all links with rel="external" or class="external" or those that link to external sources
 * @author  Stephen Blignault
 * @version 2009/05/18
 */
function external_links()
{
 // turn rel="external" attributes into new window popups
 $('a[rel^="external"]').click( function() {
  window.open( $(this).attr('href') );
  return false;
 });
 // turn "external" classes into new window popups
 $('a.external').click( function() {
  window.open( $(this).attr('href') );
  return false;
 });
 // find all external links on a site and make new window popups
 $("a[href^='http://']").not("a[href^='http://smetax.co.nz']").not("a[href^='http://www.smetax.co.nz']").not("a[href^='http://smetax.corecms.co.nz']").not('a[rel^="external"]').click(function(){
  window.open(this.href,'external');
  return false;
 });
};


function _copyPaste()
{
	// if name field is empty and check box is checked, then by default remove check on checkbox
	if ( $("input#signuptonews:checked").val() == "Yes" &&
			( $("input#RFullName").val() == "" || $("input#REmailAddress").val() == "" ) ) {
		$("input#signuptonews").attr("checked",false);
	}
	
	if ( $("input#signuptonews:checked").val() == "Yes" ) {
		$("input#CLFullName").val($("input#RFullName").val());
		$("input#CLEmailAddress").val($("input#REmailAddress").val());
	} else {
		$("input#CLFullName").val("");
		$("input#CLEmailAddress").val("");
	}
}

function copyDetails()
{	
	_copyPaste();
	$("input#signuptonews").click( function () { _copyPaste(); });
	$("input#RFullName").blur( function () { _copyPaste(); });
	$("input#REmailAddress").blur( function () { _copyPaste(); });
}

function submitNews() {
	if ( $("input#signuptonews:checked").val() == "Yes" ) {
		$("#newsform").submit();
	}
}

// Dom Load
$(function()
{
	
	copyDetails();
	external_links();
	Shadowbox.init({
		skipSetup: true,
   		players: ["flv"]
	});
	
	

	
	$('#navsub_520645_290953').hide();
	$('#get-report a').hover(function() {
		$('#navsub_520645_290953').show('fast');
		return false;
	});


	if  ( $("#get-report").hasClass("selected")  ) {
		$('#navsub_520645_290953').show();
		$("#nav").mouseleave(function(){
				$('#navsub_520645_290953').show();					   
		});
	
	}
	else {
	
		$("#nav").mouseleave(function(){
			$('#navsub_520645_290953').hide('slow');					   
		});
	
	}
	
	$('#cycle').cycle({ fx:'fade', speed: 3900, delay: -2100, random:1 });
		
	// Email Converter
	$('a.email').each(function(){
			e = this.title.replace('+','@');
			this.href=" ";
			this.href = 'mailto:' + e; $(this).text(e);
	});
	

	$("#comments-list div.citem").quickpaginate({ perpage: 4, showcounter: true, pager : $("#comments-list-counter") });


});

window.onload = function(){
    // set up all anchor elements with a "movie" class to work with Shadowbox
    Shadowbox.setup("a.video", {
        gallery:            "Media Videos",
        autoplayMovies:     true,
		height:     340,
        width:      560
    });

};




