$(document).ready(function(){
	
	
	feedback_form();
	pngfix();
	pop_up();
	image_rotator();
	nav_images();
	accordion();
	tabs();
	tabs_quote();
	
	    $('#slider1').bxSlider({
		pager: true,
		pause: 6000, 
		auto: true
		});

		$('#slider2').bxSlider({
		controls: false,
		pause: 5000,  
		auto: true
		});
			$(".video").click(function() {
							$.fancybox({
								'padding'		: 0,
								'autoScale'		: false,
								'transitionIn'	: 'none',
								'transitionOut'	: 'none',
								'title'			: this.title,
								'width'			: 640,
								'height'		: 385,
								'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
								'type'			: 'swf',
								'swf'			: {
								'wmode'				: 'transparent',
								'allowfullscreen'	: 'true'
								}
							});
							return false;
						});
	
						$(".calculators").fancybox({
									'width'				: 660,
									'height'			: 465,
									'autoScale'			: false,
									'transitionIn'		: 'slow',
									'transitionOut'		: 'none',
									'type'				: 'iframe'							
							});
	

	media();

	/*
	$(".application").validate();
	$("#loancalc").validate();
	$("#short_quick_quote").validate();
	$("#request_a_call").validate();
	*/
			
	

	

	

	
	
	
});
 
this.feedback_form = function(){
	
	var obj = $('#feedback');
	var openText = "Send us your feedback";
	var closeText = "Close feedback form";
	var left = obj.css('left');
	var speed = 500;
	
	$('<span class="open">'+ openText +'</span>').appendTo(obj).toggle(
		function(){
			$(this).removeClass('open').addClass('close').text(closeText);
			obj.animate(
				{ 'left':'0px' },	
				speed
			)
		},
		function(){
			$(this).removeClass('close').addClass('open').text(openText);
			obj.animate(
				{ 'left':left },	
				speed
			)
		}
	)
	
};


/* png fix */
this.pngfix=function(){var ie55=(navigator.appName=="Microsoft Internet Explorer"&&parseInt(navigator.appVersion)==4&&navigator.appVersion.indexOf("MSIE 5.5")!=-1);var ie6=(navigator.appName=="Microsoft Internet Explorer"&&parseInt(navigator.appVersion)==4&&navigator.appVersion.indexOf("MSIE 6.0")!=-1);if(jQuery.browser.msie&&(ie55||ie6)){$("*").each(function(){var bgIMG=$(this).css('background-image');if(bgIMG.indexOf(".png")!=-1){var iebg=bgIMG.split('url("')[1].split('")')[0];$(this).css('background-image','none');$(this).get(0).runtimeStyle.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+iebg+"',sizingMethod='crop')"}})}};

this.pop_up = function() {
	//When you click on a link with class of poplight and the href starts with a # 
$('a.poplight[href^=#]').click(function() {
    var popID = $(this).attr('rel'); //Get Popup Name
    var popURL = $(this).attr('href'); //Get Popup href to define size

    //Pull Query & Variables from href URL
    var query= popURL.split('?');
    var dim= query[1].split('&');
    var popWidth = dim[0].split('=')[1]; //Gets the first query string value

    //Fade in the Popup and add close button
    $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="assets/images/icons/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');

    //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
    var popMargTop = ($('#' + popID).height() + 80) / 2;
    var popMargLeft = ($('#' + popID).width() + 80) / 2;

    //Apply Margin to Popup
    $('#' + popID).css({
        'margin-top' : -popMargTop,
        'margin-left' : -popMargLeft
    });

    //Fade in Background
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

    return false;
});

//Close Popups and Fade Layer
$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  //fade them both out
    });
    return false;
});
}




this.image_rotator = function() {


//Show the paging and activate its first link
$(".paging").show();
$(".paging a:first").addClass("active");

//Inject <span> for Tool tip
		$(this).find(".image_reel a").append("<span></span>");
		$(this).find(".image_reel span").css({"opacity" : "0"});

//Get size of the image, how many images there are, then determin the size of the image reel.
var imageWidth = $(".window").width();
var imageSum = $(".image_reel img").size();
var imageReelWidth = imageWidth * imageSum;

//Adjust the image reel to its new size
$(".image_reel").css({'width' : imageReelWidth});

//Paging  and Slider Function
rotate = function(){
    var triggerID = $active.attr("rel") - 1; //Get number of times to slide
    var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

    $(".paging a").removeClass('active'); //Remove all active class
    $active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

    //Slider Animation
    $(".image_reel").animate({
        left: -image_reelPosition
    }, 500 );

}; 

//Rotation  and Timing Event
rotateSwitch = function(){
    play = setInterval(function(){ //Set timer - this will repeat itself every 7 seconds
        $active = $('.paging a.active').next(); //Move to the next paging
        if ( $active.length === 0) { //If paging reaches the end...
            $active = $('.paging a:first'); //go back to first
        }
        rotate(); //Trigger the paging and slider function
    }, 5000); //Timer speed in milliseconds (7 seconds)
};

rotateSwitch(); //Run function on launch
	

//On Hover
$(".image_reel a").hover(function() {
	$(this).find("span").stop().animate({ opacity: 0.7}, 200 ).show();
    clearInterval(play); //Stop the rotation
	
}, function() {
	$(this).find("span").stop().animate({ opacity: 0}, 200 ).show();
    rotateSwitch(); //Resume rotation timer
	
});	



//On Click
$(".paging a").click(function() {
    $active = $(this); //Activate the clicked paging
    //Reset Timer
    clearInterval(play); //Stop the rotation
    rotate(); //Trigger rotation immediately
    rotateSwitch(); // Resume rotation timer
    return false; //Prevent browser jump to link anchor
});
	

}


this.nav_images = function() {

	$(".ddc2 li a").hover(function(){
	
		var largePath = $(this).attr("rel");
		var largeAlt = $(this).attr("title");
		
		$("#nav_image_personal").attr({ src: largePath, alt: largeAlt });
		
	});
	
	$(".ddc2 li a").hover(function(){
	
		var largePath = $(this).attr("rel");
		var largeAlt = $(this).attr("title");
		
		$("#nav_image_business").attr({ src: largePath, alt: largeAlt });
		
	});
	
	$(".ddc2 li a").hover(function(){
	
		var largePath = $(this).attr("rel");
		var largeAlt = $(this).attr("title");
		
		$("#nav_image_insurance").attr({ src: largePath, alt: largeAlt });
		
	});
	
	$(".ddc2 li a").hover(function(){
	
		var largePath = $(this).attr("rel");
		var largeAlt = $(this).attr("title");
		
		$("#nav_image_about").attr({ src: largePath, alt: largeAlt });
		
	});
	
}

//accordion

this.accordion = function() {
	//Set default open/close settings
$('.acc_container').hide(); //Hide/close all containers
$('.acc_trigger:first').addClass('active').next().show(); //Add "active" class to first trigger, then show/open the immediate next container

//On Click
$('.acc_trigger').click(function(){
	if( $(this).next().is(':hidden') ) { //If immediate next container is closed...
		$('.acc_trigger').removeClass('active').next().slideUp(); //Remove all "active" state and slide up the immediate next container
		$(this).toggleClass('active').next().slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container
	}
	return false; //Prevent the browser jump to the link anchor
});
}


// tabs

this.tabs = function()  {

	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:eq(0)").addClass("active").show(); //Activate second tab
	$(".tab_content:eq(0)").show(); //Show second tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});

}

this.tabs_quote = function()  {

	//When page loads...
	$(".tab_content_quote").hide(); //Hide all content
	$("ul.tabs_quote li:eq(0)").addClass("active").show(); //Activate first tab
	$(".tab_content_quote:eq(0)").show(); //Show first tab content

	//On Click Event
	$("ul.tabs_quote li").click(function() {

		$("ul.tabs_quote li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content_quote").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});

}

this.media = function() {

		$("#jquery_jplayer_1").jPlayer({
			ready: function () {	
				$(this).jPlayer("setMedia", {
					mp3: "http://www.natloans.com.au/assets/audio/otr1.mp3",
					oga: "http://www.natloans.com.au/assets/audio/otr1.ogg"
				}).jPlayer("stop");
			},
			ended: function (event) {
				$("#jquery_jplayer_2").jPlayer("play", 0);
			},
			swfPath: "assets/js/",
			solution: "flash, html",
			supplied: "mp3, oga"
		})
		.bind($.jPlayer.event.play, function() { // Using a jPlayer event to avoid both jPlayers playing together.
				$(this).jPlayer("pauseOthers");
		});
		
		$("#jquery_jplayer_2").jPlayer({
			ready: function () {
				$(this).jPlayer("setMedia", {
					mp3: "http://www.natloans.com.au/assets/audio/otr2.mp3",
					oga: "http://www.natloans.com.au/assets/audio/otr2.ogg"
				});
			},
			ended: function (event) {
				$("#jquery_jplayer_1").jPlayer("play", 0);
			},
			swfPath: "assets/js/",
			solution: "flash, html",
			supplied: "mp3, oga",
			cssSelectorAncestor: "#jp_interface_2"
		})
		.bind($.jPlayer.event.play, function() { // Using a jPlayer event to avoid both jPlayers playing together.
				$(this).jPlayer("pauseOthers");
		});
		
		
		
			$("#jquery_jplayer_3").jPlayer({
				ready: function () {
					$(this).jPlayer("setMedia", {
						mp3: "http://www.natloans.com.au/assets/audio/otr3.mp3",
						oga: "http://www.natloans.com.au/assets/audio/otr3.ogg"
					}).jPlayer("stop");
				},
				ended: function (event) {
					$(this).jPlayer("play");
				},
				swfPath: "assets/js/",
				solution: "flash, html",
				supplied: "mp3, oga",
				cssSelectorAncestor: "#jp_interface_3"
			})
			.bind($.jPlayer.event.play, function() { // Using a jPlayer event to avoid both jPlayers playing together.
					$(this).jPlayer("pauseOthers");
			});
			
			
			$("#jquery_jplayer_4").jPlayer({
				ready: function () {
					$(this).jPlayer("setMedia", {
						mp3: "http://www.natloans.com.au/assets/audio/otr4.mp3",
						oga: "http://www.natloans.com.au/assets/audio/otr4.ogg"
					}).jPlayer("stop");
				},
				ended: function (event) {
					$(this).jPlayer("play");
				},
				swfPath: "assets/js/",
				solution: "flash, html",
				supplied: "mp3, oga",
				cssSelectorAncestor: "#jp_interface_4"
			})
			.bind($.jPlayer.event.play, function() { // Using a jPlayer event to avoid both jPlayers playing together.
					$(this).jPlayer("pauseOthers");
			});
			
			
			$("#jquery_jplayer_5").jPlayer({
				ready: function () {
					$(this).jPlayer("setMedia", {
						mp3: "http://www.natloans.com.au/assets/audio/otr5.mp3",
						oga: "http://www.natloans.com.au/assets/audio/otr5.ogg"
					}).jPlayer("stop");
				},
				ended: function (event) {
					$(this).jPlayer("play");
				},
				swfPath: "assets/js/",
				solution: "flash, html",
				supplied: "mp3, oga",
				cssSelectorAncestor: "#jp_interface_5"
			})
			.bind($.jPlayer.event.play, function() { // Using a jPlayer event to avoid both jPlayers playing together.
					$(this).jPlayer("pauseOthers");
			});
			
			$("#jquery_jplayer_6").jPlayer({
				ready: function () {
					$(this).jPlayer("setMedia", {
						mp3: "http://www.natloans.com.au/assets/audio/otr6.mp3",
						oga: "http://www.natloans.com.au/assets/audio/otr6.ogg"
					}).jPlayer("stop");
				},
				ended: function (event) {
					$(this).jPlayer("play");
				},
				swfPath: "assets/js/",
				solution: "flash, html",
				supplied: "mp3, oga",
				cssSelectorAncestor: "#jp_interface_6"
			})
			.bind($.jPlayer.event.play, function() { // Using a jPlayer event to avoid both jPlayers playing together.
					$(this).jPlayer("pauseOthers");
			});
			
			$("#jquery_jplayer_7").jPlayer({
				ready: function () {
					$(this).jPlayer("setMedia", {
						mp3: "http://www.natloans.com.au/assets/audio/otr7.mp3",
						oga: "http://www.natloans.com.au/assets/audio/otr7.ogg"
					}).jPlayer("stop");
				},
				ended: function (event) {
					$(this).jPlayer("play");
				},
				swfPath: "assets/js/",
				solution: "flash, html",
				supplied: "mp3, oga",
				cssSelectorAncestor: "#jp_interface_7"
			})
			.bind($.jPlayer.event.play, function() { // Using a jPlayer event to avoid both jPlayers playing together.
					$(this).jPlayer("pauseOthers");
			});
			
			$("#jquery_jplayer_8").jPlayer({
				ready: function () {
					$(this).jPlayer("setMedia", {
						mp3: "http://www.natloans.com.au/assets/audio/8.mp3",
						oga: "http://www.natloans.com.au/assets/audio/8.ogg"
					}).jPlayer("stop");
				},
				ended: function (event) {
					$(this).jPlayer("play");
				},
				swfPath: "assets/js/",
				solution: "flash, html",
				supplied: "mp3, oga",
				cssSelectorAncestor: "#jp_interface_8"
			})
			.bind($.jPlayer.event.play, function() { // Using a jPlayer event to avoid both jPlayers playing together.
					$(this).jPlayer("pauseOthers");
			});
			
			$("#jquery_jplayer_9").jPlayer({
				ready: function () {
					$(this).jPlayer("setMedia", {
						mp3: "http://www.natloans.com.au/assets/audio/9.mp3",
						oga: "http://www.natloans.com.au/assets/audio/9.ogg"
					}).jPlayer("stop");
				},
				ended: function (event) {
					$(this).jPlayer("play");
				},
				swfPath: "assets/js/",
				solution: "flash, html",
				supplied: "mp3, oga",
				cssSelectorAncestor: "#jp_interface_9"
			})
			.bind($.jPlayer.event.play, function() { // Using a jPlayer event to avoid both jPlayers playing together.
					$(this).jPlayer("pauseOthers");
			});
			
			$("#jquery_jplayer_10").jPlayer({
				ready: function () {
					$(this).jPlayer("setMedia", {
						mp3: "http://www.natloans.com.au/assets/audio/10.mp3",
						oga: "http://www.natloans.com.au/assets/audio/10.ogg"
					}).jPlayer("stop");
				},
				ended: function (event) {
					$(this).jPlayer("play");
				},
				swfPath: "assets/js/",
				solution: "flash, html",
				supplied: "mp3, oga",
				cssSelectorAncestor: "#jp_interface_10"
			})
			.bind($.jPlayer.event.play, function() { // Using a jPlayer event to avoid both jPlayers playing together.
					$(this).jPlayer("pauseOthers");
			});
			
			$("#jquery_jplayer_11").jPlayer({
				ready: function () {
					$(this).jPlayer("setMedia", {
						mp3: "http://www.natloans.com.au/assets/audio/11.mp3",
						oga: "http://www.natloans.com.au/assets/audio/11.ogg"
					}).jPlayer("stop");
				},
				ended: function (event) {
					$(this).jPlayer("play");
				},
				swfPath: "assets/js/",
				solution: "flash, html",
				supplied: "mp3, oga",
				cssSelectorAncestor: "#jp_interface_11"
			})
			.bind($.jPlayer.event.play, function() { // Using a jPlayer event to avoid both jPlayers playing together.
					$(this).jPlayer("pauseOthers");
			});
			
				$("#jquery_jplayer_12").jPlayer({
					ready: function () {
						$(this).jPlayer("setMedia", {
							mp3: "http://www.natloans.com.au/assets/audio/12.mp3",
							oga: "http://www.natloans.com.au/assets/audio/12.ogg"
						}).jPlayer("stop");
					},
					ended: function (event) {
						$(this).jPlayer("play");
					},
					swfPath: "assets/js/",
					solution: "flash, html",
					supplied: "mp3, oga",
					cssSelectorAncestor: "#jp_interface_12"
				})
				.bind($.jPlayer.event.play, function() { // Using a jPlayer event to avoid both jPlayers playing together.
						$(this).jPlayer("pauseOthers");
				});
			

}


