
$(document).ready(function() {
	
	
	// ---------------------	
	//  Modal Popup
	// ---------------------

	// Load dialog on click
	has_modal = $('#modal_popup').length;
	if( has_modal != 0 ) {
		$('#modal_popup').modal({overlayClose:true});
	}
	
	
	// ---------------------	
	//  Main Menu Drop Down
	// ---------------------

	 $('.sf-menu').superfish({  
	       delay:		300,
	       speed:		200,
	       autoArrows:	false,
	       dropShadows:	false
	 });
	 
	 
	 
	// -----------------
	//  Forms
	// -----------------
	
	// IE :focus fix
	fixFocus = function() {
		var fEls = document.getElementsByTagName("INPUT");
		//for (var i=0; i<sfEls.length; i++) {
		for (var i=0; i<fEls.length; i++) {
			fEls[i].onfocus=function() {
				this.className+=" focus";
			}
			fEls[i].onblur=function() {
				this.className=this.className.replace(new RegExp(" focus\\b"), "");
			}
		}
	}
	if (window.attachEvent) window.attachEvent("onload", fixFocus);
	
	
	
	// Other Payment Amount
	$('table.amount_radio input').click(function() {
		if( $('table.amount_radio input.other').is(':checked') ) {
			$('table.amount_radio td .other_amount').show();	
		} else {
			$('table.amount_radio td .other_amount').hide();
		}
	});
	
	
	// Payment Type Open Below TODO
	
	$('#payment_type.payment_radio input').click(function() {
		open_payment = $('#payment_type.payment_radio input:checked').attr('rel');
		$('#payment_options_list .type').hide();
		$('#payment_options_list .type#payment_details_' + open_payment).slideDown('fast');
	});

	 
	 
	// -----------------
	//  Cycle Slideshow
	// -----------------
	
	$.slide_interval = 10 * 1000;
	$.slide_timeout = setTimeout("roll_through_slides()",$.slide_interval);
	
	
	//  Run slideshow
	// ---------------
	
	$('ul.tabs li a').click(function() {
		// Show current image
		new_slide = $(this).attr('rel');
		change_slide(new_slide);
		clearTimeout($.slide_timeout);
		$.slide_timeout = setTimeout("roll_through_slides()",$.slide_interval);
		return false;
	});
	
	
	// -----------------
	//  Cycle Tweets
	// -----------------
	/*$(".twitter_feed .tweet_list").tweet({
       avatar_size: 0,
        count: 5,
		fetch: 1,
        filter: function(t){ return ! /^@\w+/.test(t["tweet_raw_text"]); },
        username: "ausparty"
      });*/
      
      
    //  Run tweet slideshow
	// ----------------------

//	$('.twitter_feed').bind('loaded', function() {
//		$('ul.tweet_list').cycle({ 
//		    timeout: 5000,
//		    speed: 1,
//		    pause: 1,
//			pagerAnchorBuilder: function(idx, slide) { 
//				return '<a href="javascript:;">' + (idx+1) + '</a>'; // stops it auto inserting
//			},
//			activePagerClass: 'active'
//		});
//	});

	
});


function change_slide(new_slide) {
	// Change main image
	$('.slideshow .slide').removeClass('active');
	$('.slideshow .slide#slide_image_' + new_slide).addClass('active');
	
	// Show active tab
	$('ul.tabs li a').removeClass('active');
	$('ul.tabs li a[rel=' + new_slide + ']').addClass('active');
}


function roll_through_slides() {
	$.slide_timeout = setTimeout("roll_through_slides()",$.slide_interval);
	new_slide = $('ul.tabs .active').attr('rel');
	total_slides = $('ul.tabs li').length;
	
	// If current slide is last, go to start
	if( new_slide == total_slides ) {
		new_slide = 0;
	}
	new_slide++;
	change_slide(new_slide);
}


function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
	thefield.value = ""
} 


// Checks what type is currently chosen and displays further details 
function donation_form_payment_type_display() {
}

