// =============
// = Functions =
// =============

$.fn.duplicate = function(count, cloneEvents) {
	var tmp = [];
	for ( var i = 0; i < count; i++ ) {
		$.merge( tmp, this.clone( cloneEvents ).get() );
	}
	return this.pushStack( tmp );
};

// Duplicating content for the sake of filling the page


// ==================================
// = Login Status
// ==================================

var $loginStatus = $("#loginStatus");
if($loginStatus.length > 0){
	$.get(
		"/index.php?/embeds/loginstatus",
		function(data) {
			$loginStatus.hide();
			$loginStatus.html(data);
			$loginStatus.fadeIn();
		}
	)
}





// ==============
// = Generic JS =
// ==============

$('.tabbed').tabs();

// Pseudo fixes
$('#footer .content ul li:last-child').addClass('last');
$('#nav li:last-child').addClass('last');

$('.photos li:nth-child(4n)').after('<br class="clear" />');

// IE6 pngfix
$('.ie6 .fix').supersleight({shim: '/images/assets/x.gif'});

// Fancybox
$(".photos li a").fancybox({
	'overlayOpacity'	: 0.8,
	'overlayColor'		: '#000',
	'titlePosition' 	: 'inside'
});


//Speaker Bio
$("a.eventSpeakerBioShow").click(function() {
	$(this).parent().next().css("display", "block");
	$(this).hide();
	return false;
})

$("a.speakerLink").click(function() {
	$(this).parent().find("a.eventSpeakerBioShow").trigger("click");
	return false;
})
$("a.speakerLink2").click(function() {
	$(this).parent().parent().find("a.eventSpeakerBioShow").trigger("click");
	return false;
})

$("a.eventSpeakerBioHide").click(function() {
	$(this).parent().parent().css("display", "none");
	$(this).parent().parent().prev().children().show();

	return false;
})


//Publication quantity
$("#publicationQtySelect").change(function() {
	var price	= parseFloat($("#price").text());
	var tax		= parseFloat($("#tax").text());
	var postage	= parseFloat($("#postage").text());
	var $total	= $("#total");
	var qty  	= $(this).val();
	
	var newTotal = (price + tax + postage) * qty;

	$total.text(newTotal.toString());
})


// Add pdf icons to pdf links
$("a[href$='.pdf']").addClass("pdf");
// Add doc icons to document links (docx, doc, rtf, txt)
$("a[href$='.docx'], a[href$='.doc'], a[href$='.txt'], a[href$='.rft']").addClass("doc");
// Add powerpoint icons to powerpoint file links (pptx, ppt)
$("a[href$='.ppt'], a[href$='.pptx']").addClass("ppt"); 

// Jquery Slider
var $slider = $('.slider');

if($slider.length > 0){
	$slider.before('<div id="slider-nav">').cycle({ 
		timeout: 5000,
		pager:  '#slider-nav' 
	});
}

