

/* START	smartline.js 	----------------------------------------------------------------------------------------------------------------------------------------	*/



	function mfHandler() {
		$("a[href=/").attr("href", "http://www.mortgageforce.com.au");
		$("a[href=http://www.smartline.com.au]").attr("href", "http://www.mortgageforce.com.au");
		$("a[href=http://www.smartline.com.au/]").attr("href", "http://www.mortgageforce.com.au");
		$("a[href=http://www.smartline.com.au/index.html]").attr("href", "http://www.mortgageforce.com.au");
				
		$("a[href=/#mf").attr("href", "http://www.mortgageforce.com.au");
		$("a[href=http://www.smartline.com.au#mf]").attr("href", "http://www.mortgageforce.com.au");
		$("a[href=http://www.smartline.com.au/#mf]").attr("href", "http://www.mortgageforce.com.au");
		$("a[href=http://www.smartline.com.au/index.html#mf]").attr("href", "http://www.mortgageforce.com.au");
	}

	function cookieChecker() {
		if (document.cookie.indexOf("mortgage=") != -1) {
		mfHandler();
		}
	}

	function setTheCookie() {
		document.cookie="mortgage=true";
	}
	
	var url = window.location.toString(),
		urlParts = url.split("/"),
		urlPartsOffset = 2;
		

$(document).ready(function() {
						   
	$("div#map > a").click(function() {
		$.scrollTo(200, 600);
		return false;
	});

	$(".button-back-to-top").click(function(e) {
		e.preventDefault();
		$.scrollTo(0, 600);
	});

	var hero = $("#hero-pannel > div"),
		heroPosition = Math.floor(Math.random() * hero.length);

	hero.attr("style", "display:none;")
		.eq(heroPosition)
		.attr("style", "display:block;");


	NavSelector();
	
	$(".navChecker li ul li a").mouseover(function() {
		$(this).parent().parent().prev().addClass("selected");
	});
	$(".navChecker li ul li a").mouseout(function() {
		$(this).parent().parent().prev().removeClass("selected");
		NavSelector();
	});

	var crumbs = [];

	crumbs[0] = new BreadCrumb("Home", "http://www.smartline.com.au", false);

	for (var i = 1; i < urlParts.length - urlPartsOffset - 1; i++) {
		crumbs[i] = new BreadCrumb(urlParts[i + urlPartsOffset],
										   urlParts[i + urlPartsOffset],
										   false);
	}

	crumbs[crumbs.length] = new BreadCrumb($(".main-heading").text(), url, true);

	//appends contents to the end of a top level nav item in the breadcrumbs.
	if (crumbs.length > 2) {
		var nameParts = crumbs[1].Href.split(".");
		nameParts[0] = nameParts[0] + "contents";
		crumbs[1].Href = nameParts.join(".");
	}

	$("ul#breadcrumbs-list").append(crumbs.join(""));
	
	if (window.location.href.indexOf("#mf") != -1) {
			setTheCookie();
			mfHandler();
	} else {
			cookieChecker();
	}

});

function NavSelector() {

	if ((urlParts.length - urlPartsOffset) > 2) {
		var iniPath = urlParts[urlParts.length - 2];
		$("ul.navChecker > li > a").each(function() {
			var theEle = $(this), theHref = theEle.attr("href");
			if (theHref.length > 1 && theHref.indexOf(iniPath) > 0) {
				theEle.addClass("selected");
				return false;
			}
		});
		//side nav
		iniPath = urlParts[urlParts.length - 1];
		$("ul.navSideChecker > li > a").each(function() {
			var theEle = $(this), theHref = theEle.attr("href");
			if (theHref.length > 1 && theHref.indexOf(iniPath) > 0) {
				theEle.addClass("selected");
				return false;
			}
		});
	}
	else {
		$("ul.navChecker > li > a").each(function() {
			var theEle = $(this), theHref = theEle.attr("href");
			if (theHref.length > 1 && url.indexOf(theHref) > 0) {
				theEle.addClass("selected");
				return false;
			}
		});
	}
}

function BreadCrumb(title, href, current) {
	this.Title = TitlePrepare(title);
	this.Href = HrefPrepare(href);
	this.Current = current;

	function TitlePrepare(title) {
		var wordBlocks = title.split("-");
		if (wordBlocks.length > 1) {
			for (var i = 0; i < wordBlocks.length; i++) {
				wordBlocks[i] = wordBlocks[i].substring(0, 1).toUpperCase() + wordBlocks[i].substring(1, wordBlocks[i].length);
			}
			return wordBlocks.join(" ");
		}
		else {
			return title;
		}
	}

	function HrefPrepare(href) {
		if (current || href == "http://www.smartline.com.au") {
			return href;
		}
		else {
			var hrefURL = href.split("/");
			hrefURL[hrefURL.length - 1] = hrefURL[hrefURL.length - 1].replace(/-/g, "") + ".html";
			return hrefURL.join("");
		}
	}
}



BreadCrumb.prototype.toString = function() {
	var isCurrent = "";
	if (this.Current) {
		isCurrent = "class=\"current\"";
	}
	return "<li {0}><a href=\"{1}\" title=\"{2}\">{2}</a></li>".format(isCurrent, this.Href, this.Title);


};

String.prototype.format = function() {
	var pattern = /\{\d+\}/g;
	var args = arguments;
	return this.replace(pattern, function(capture) { return args[capture.match(/\d+/)]; });
};

$(document).ready(function() {
	$('#lenders-logos').cycle({
		fx: 'fade',
		random: 1,
		speed: 2000
	});
});


/* END 		smartline.js	----------------------------------------------------------------------------------------------------------------------------------------	*/



/* START	new-template.js 	----------------------------------------------------------------------------------------------------------------------------------------	*/




$(document).ready(function () {

    //Script for rotator on home page

    $('#home-pods').css('height', '228px').find('.pods').css({
        height: '215px',
        overflow: 'hidden'
    });


    $('#home-pods .nav a:first').addClass('active');

    //News rotator	



    if (jQuery.fn.NewsRotator) {
        var homePod = $('#home-pods .pods').NewsRotator({
            interval: 8000,
            items_query: '.items',
            item_query: '.item',
            image_query: '.image',
            orientation: 'horizontal',
            current_class: 'current',
            duration: 700,
            easing: "easeInOutExpo",

            beforeSlide: function () {//Before starting the rotation

                var pos = 0;
                $('#home-pods .nav a').each(function ($key, $value) {
                    if ($(this).hasClass('active')) {
                        pos = ($key + 1);
                        $(this).removeClass('active');
                    }
                });
                if (pos > 3) pos = 0;
                $('#home-pods .nav a').eq(pos).addClass('active');

            }

        });


		
		
		$('#home-pods .nav a')
		
			.click(function ($e) {
            	//$e.preventDefault();
			})
			
			.mouseover(function(){
				var obj = this;
				var pos = 0;
				$('#home-pods .nav a').each(function ($key, $value) {
					if ($(this).text() == $(obj).text())pos = $key;
				});
	
				$('#home-pods .nav a').removeClass('active').eq(pos).addClass('active');
	
				homePod.moveTo(pos);
        	});
		
    }


});





/* END 		new-template.js	----------------------------------------------------------------------------------------------------------------------------------------	*/



