jQuery(document).ready(function($) {

	$(".projects").hover(function() {
		$(this).find(".projects_img_overlay").first().fadeIn(200);
	},
	function() {
		$(this).find(".projects_img_overlay").first().fadeOut(200);
	});

	/* Activate the tabs if there is any */
	$("ul.tabs").tabs("div.panes > div");

	/* Add effects to members search */
	$("div.tern_members_search form").hide();

	$("#search_members_button").toggle(function() {
		$("div.tern_members_search form").slideDown();
		$(this).html("SEARCH OUR STAFF &laquo;");
	},
	function () {
		$("div.tern_members_search form").slideUp();
		$(this).html("SEARCH OUR STAFF &raquo;");
	});
		
	/*$("form#projectSearchFormWide span#search_our_projects").toggle(function() {
		$("div#project_search_form_contents").slideDown();
		$(this).html("SEARCH OUR PROJECTS &laquo;");
	},
	function () {
		$("div#project_search_form_contents").slideUp();
		$(this).html("SEARCH OUR PROJECTS &raquo;");
	});
	
	$("div#project_search_form_contents").hide();*/
	
	if ($("div.projects").size() <= 0) {
		$("form#projectSearchFormWide span#search_our_projects").click();
	}

	/*$('.hcard-vcard-generator-widget div.email_button span.redbutton, div.user_details a.email span, div.tern_wp_members_user_email a.email span, p.email_button a.greybutton span').colorbox({
		width: "400px",
		height: "550px;",
		html: function() {
			return $(this).parent().parent().next('div.contact_form').html();
		},
		opacity: 0.5,
		returnFocus: false,
		overlayClose: false
	});*/
	
	$('.hcard-vcard-generator-widget div.email_button a, div.user_details a.email, div.tern_wp_members_user_email a.email, p.email_button a.greybutton').each(function() {
		$(this).fancybox({
			titleShow: false
		});
	});
	
	/*$('.job-listing .littlebutton span').colorbox({
		width: "450px",
		height: "550px;",
		html: function() {
			return $(this).parent().parent().next('div.contact_form').html();
		},
		opacity: 0.5,
		returnFocus: false,
		onComplete: function() {
			var job_subject = $(this).parent().parent().find('h3').first().html();
			$('#cboxContent').find('span.your-subject input').val('Job Enquiry: ' + job_subject);
		}
	});*/
	
	$('.job-listing .littlebutton').each(function() {
		$(this).fancybox({
			onComplete: function(thisobj) {
				var job_subject = $(thisobj).parent().parent().find('h3').first().html();
				$('#fancybox-inner').find('span.your-subject input').val('Job Enquiry: ' + job_subject);
			},
			titleShow: false
		});
			
	});
	
	$(".tern_wp_members_list li").hover(function() {
		$(this).find('img').stop() /* Add class of "hover", then stop animation queue buildup*/
			.animate({
				opacity: '1'
			}, 
			300,
			'easeOutQuad');
		
		$(this).find('div.tern_wp_member_info').animate({
			height: '0px',
			marginTop: '115px',
			opacity: '0'
		}, 500);
		
	} , function() {
		$(this).find('img').css({'z-index' : '0'}); /* Set z-index back to 0 */
		$(this).find('img').stop()  /* Remove the "hover" class , then stop animation queue buildup*/
			.animate({
				opacity: '0.8'
			},
			300,
			'easeOutQuad');
			
		$(this).find('div.tern_wp_member_info').animate({
			height: '38px',
			marginTop: '71px',
			opacity: '0.8'
		}, 500);
	});
	
	
	/* Add the CP logo and hover thingo */
	$('<img>').attr({
		"id": "menu-logo-image",
		"src": tern_wp_root + "/wp-content/themes/cottee/images/menu-item-home.png",
		"alt": "Cottee Parker Architects"
	}).appendTo(".menu-item-home a");
	
	$('<img>').attr({
		"id": "logo-hover-outline",
		"src": tern_wp_root + "/wp-content/themes/cottee/images/logo-hover-outline.png",
		"alt": "Cottee Parker Architects"
	}).appendTo(".menu-item-home");
	
	$(".menu-item-home").hover(function() {
		$(this).find('#logo-hover-outline').fadeIn(400);
		
	},
	function() {
		$(this).find('#logo-hover-outline').fadeOut(400);
	});
	
});

function projectSearchResultPageSelect(page_index, jq) {
	var items_per_page = 15;
	var max_elem = Math.min((page_index+1) * items_per_page, jQuery('#hiddenresult .paginateme').length);
	jQuery('#projectSearchResult').empty();
		
	for (var i=page_index * items_per_page; i < max_elem; i++) {
		new_content = jQuery('#hiddenresult .paginateme:eq('+i+')').clone();
		jQuery('#projectSearchResult').append(new_content);
	}
	
	jQuery("html, body").animate({scrollTop:0}, 200, 'easeOutQuad');
	
	return false;
}


function initPagination() {
	// count entries inside the hidden content
	var num_entries = jQuery('#hiddenresult .paginateme').length;
	// Create content inside pagination element
	jQuery(".projectSearchResultPagination").pagination(num_entries, {
		callback: projectSearchResultPageSelect,
		items_per_page: 15,
		num_edge_entries: 1
	});
}


