/**
 * Add default "temporary" text to inputs
 * Courtesy of http://dabrook.org/blog/articles/input-field-hints-plugin-for-jquery/
 */
jQuery.fn.inputFieldText = function(string, hintClass) {
  this.each(function() {
      $(this).addClass(hintClass).filter(function(){
      	return ($(this).val() == '' || $(this).val() == string);
      }).val(string);
      $(this).focus(function(){
        if ($(this).val() == string){
          $(this).removeClass(hintClass).val('');
        }
      });
      $(this).blur(function(){
        if ($(this).val() == ''){
          $(this).addClass(hintClass).val(string);
        }
      });
  });
};


if (swfobject.hasFlashPlayerVersion('9.0.115')) {
	swfobject.embedSWF('http://www.qpu.asn.au/swf/CampaignViewer.swf', 'CampaignViewer', '756', '340', '9.0.115', null, {urlPrefix:'http://www.qpu.asn.au', dataPath:'/campaigns/no_cop_out.json', embedded:1}, {wmode:'window', allowfullscreen:'true', allowScriptAccess:'always'});
} else {
	$(function(){
		$('.noflash').each(function(){
			$(this).replaceWith($($(this).text()));
		});
	});
}

$(function(){
	$("div.newsCarousel").carousel({
		dispItems: 3,
		showEmptyItems:false,
		slideEasing: 'easeOutQuart',
		combinedClasses: true,
		animSpeed: 700
	}).find('LI').show();
	// bit of hack we need to get it right
	$('#right-separator').css({marginLeft:'16px'});
});

$(function(){
	$("div.newsViewCarousel").carousel({
		dispItems: 1,
		slideEasing: 'easeOutQuart',
		animSpeed: 700
	}).find('LI').show();
});


$(function(){
	
	$("#MemberPassword").hide();
	var new_input = document.createElement("input");
	new_input.setAttribute("id", 'Password_hidden');
	new_input.setAttribute("type","text");
	new_input.value = 'Password';
	$("#MemberPassword").after(new_input);
	$('#Password_hidden').focus(function(){

		$(this).hide().prev().show().focus();
	});
	$("#MemberPassword").blur(function(){
		if ($(this).val() == '') {
			$(this).hide().next().show();
		}
	});
	
	$('#header-login LABEL').each(function(){
		$('#'+$(this).attr('for')).inputFieldText($(this).text(), 'hint');
	}).hide();
	
});

$(function(){
	
	if (!$.fn.fancybox) {
		return;
	}
	
	// do images
	$('a.newsitem-image').fancybox({
		zoomSpeedIn:400,
		zoomSpeedOut:400,
		overlayShow: true,
		overlayColor: '#000',
		overlayOpacity: 0.8,
		hideOnContentClick:false
	});
	
	$('a.survey').fancybox({
		zoomSpeedIn:400,
		zoomSpeedOut:400,
		frameWidth: 800,
		frameHeight: 600,
		overlayShow: true,
		overlayColor: '#000',
		overlayOpacity: 0.8,
		hideOnContentClick:false
	});
	
	// do videos
	$('BODY').append('<div style="display:none" id="video"></div>').append('<a href="#video" id="videoLink" />');	
	$('a.newsitem-video').click(function(evt){
		
		var videoDetails = $(this).metadata({type:'attr', name:'data'});
		videoDetails.url = $(this).attr('href');
		videoDetails.title = $(this).attr('title');

		var flashvars = {
			autostart:'true', repeat:'false',
			width:videoDetails.width,
			height:videoDetails.height+20,
			file:videoDetails.url
		};
			
		$('#videoLink').css({position:'absolute', top:evt.pageY, left:evt.pageX}).fancybox({
			callbackOnShow:function(){
				$('#fancy_content').html('<div id="fancy_video"></div>');
				swfobject.embedSWF('/swf/player.swf', 'fancy_video', videoDetails.width, videoDetails.height+20, '9.0.115', null, flashvars, {allowfullscreen:'true'});
			},
			callbackBeforeClose:function() {
				$('#fancy_content').empty();
			},
			zoomSpeedIn:400,
			zoomSpeedOut:400,
			frameWidth:videoDetails.width,
			frameHeight:videoDetails.height+20,
			overlayShow: true,
			overlayColor: '#000',
			overlayOpacity: 0.8,
			hideOnContentClick:false
		}).trigger('click');
		
		return false;
		
	});
	
	$('a.newsitem-audio').click(function(evt){
		
		var videoDetails = [];
		videoDetails.url = $(this).attr('href');
		videoDetails.title = $(this).attr('title');

		var flashvars = {
			autostart:'true', repeat:'false',
			file:videoDetails.url,
			volume: 100
		};
			
		$('#videoLink').css({position:'absolute', top:evt.pageY, left:evt.pageX}).fancybox({
			callbackOnShow:function(){
				$('#fancy_content').html('<div id="fancy_video"></div>');
				swfobject.embedSWF('/swf/player.swf', 'fancy_video', 400, 20, '9.0.115', null, flashvars, {allowfullscreen:'true'});
			},
			callbackBeforeClose:function() {
				$('#fancy_content').empty();
			},
			zoomSpeedIn:400,
			zoomSpeedOut:400,
			frameWidth:400,
			frameHeight:20,
			overlayShow: true,
			overlayColor: '#000',
			overlayOpacity: 0.8,
			hideOnContentClick:false
		}).trigger('click');
		return false;
	});
});
