 /*-----------------------------------------------
'	Company: Community Engine (www.communityengine.com)
'	Copyright (c) 2009, All rights reserved.
'	Date Created: April 2009
'
'	Last Modified Date: 17th December 2009
'	Last Modified By: James // james.cooke@communityengine.com.au
'
'	DO NOT MODIFY THIS DOCUMENT WITHOUT
'	NOTIFYING THE AUTHOR FIRST
'
------------------------------------------------*/
var $j = jQuery.noConflict();
// Kentico media library affects jQuery so use $j NOT $

$j(function() {

	setupRSS();

	$j('.slider').anythingSlider({
		easing: "swing",        // Anything other than "linear" or "swing" requires the easing plugin
		autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
		delay: 5000,                    // How long between slide transitions in AutoPlay mode
		startStopped: false,            // If autoPlay is on, this can force it to start stopped
		animationTime: 1000,             // How long the slide transition takes
		hashTags: true,                 // Should links change the hashtag in the URL?
		buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
		pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
		startText: "Go",             // Start text
		stopText: "Stop"               // Stop text
	});

	//$j(".user-control-tabs .tab-header").controlTabs();
	$j("ul.top-nav").supersubs({
		maxWidth: 40,
		extraWidth: 1
	}).superfish({
		hoverClass: "hover",
		animation: { opacity: 'show', height: 'show' },
		delay: 1400,
		autoArrows: false
	});
	$j(".valueclear").valueClear();

	//$j('.footer dl').equalCols();
	$j('.module-group-list li').equalCols();
	$j('.main-column, .right-column').equalCols()
	$j('.main-content .col-right, .main-content .col-2').equalCols();

	$j('a[rel="external"]').live("click", function() {
		window.open(this.href);
		return false;
	});
	
	$j(".colorwindow:not([href=#])").colorbox({
		transition: "elastic",
		photo: true
	});
	
	if ($j('.module-gallery li').length) {
		$j('.module-gallery li').equalRow().addLast();
	}
	

$j(".defaultVal").defaultVal();
});

jQuery.fn.valueClear = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};

jQuery.fn.defaultVal = function() {
    return this.focus(function() {
        if (this.value == this.defaultValue) {
            this.value = "";
        }
    }).blur(function() {
        if (!this.value.length) {
            this.value = this.defaultValue;
        }
    });
};



jQuery.fn.equalCols = function() {
	var sortNumber = function(a, b) { return b - a; };
	var heights = [];
	$j(this).each(function() {
		heights.push($j(this).height());
	});
	heights.sort(sortNumber);
	var maxHeight = heights[0];
	return this.each(function() {
		$j(this).css({ 'min-height': maxHeight }); // Do a fix for IE
	//	console.log(maxHeight);
	});
};



jQuery.fn.controlTabs = function(options){

	/* Fool proof tab, checks if the tab has a control-item and displays, if not it follows the link */

	
	return this.each(function(){
		
		$j(this).click(function(){
			if($(this).siblings(".control-item").length > 0){
				$j(".user-control-tabs li").removeClass("on");
				$j(this).closest("li").addClass("on");
				$j(this).closest("div").attr("id", $j(this).attr("rel"));
				return false;
			}
		});
	});
};

function setupRSS() {
	
	$j.jGFeed(
		'http://www.alp.org.au/feeds/blogs/rss.xml',
		function(feeds) {
			var blogOutput = "";
			if (!feeds) {
				// hide entries
				$j("#labor-rss").hide();
				return false;
			}
			for (var i = 0; i < feeds.entries.length; i++) {
				var entry = feeds.entries[i];
				var publishedDate = entry.publishedDate.substr(0, 17);
				blogOutput += "<dd><a href='" + entry.link + "' title='" + entry.title + "' rel='external'>" + entry.title + "</a></dd>\n";
			}
			$j("#labor-rss").append(blogOutput);
			$j('.footer dl').equalCols();
		},
	4);
}
