Cufon.replace('#leftMenu ul li, .titlebar h2', { hover: true, fontFamily: 'Verlag' });
Cufon.replace('#image .container p, #mainNav, .container h3, #leftMenu', { fontFamily: 'Verlag'});
Cufon.replace('#mainNav ul li', { fontFamily: 'Helv'});



$(function(){
	
	//*-----AJAX PAGE ONLOAD-----*//

		var pathname = window.location.href;
		var hashnum = strrpos(pathname, '#');
		if (hashnum != false){
			var ajaxname = pathname.substr(hashnum + 7);
		}else{
			var ajaxname = false;
		}
		if(ajaxname != false){
			$('#email-login').val(ajaxname); 
			$('#modal_login').jqm({trigger: 'a.trigger_login', toTop: true});
			$('#modal_login').jqmShow(); 
		}
	
	
	
	/*$("#CompanyTypeOther").hide();
	if($("#CompanyType").val().indexOf("Other") != -1) {$("#CompanyTypeOther").fadeIn();}


	$("#CompanyType").change(function(){
		$("#CompanyTypeOther").fadeOut();
		if($("#q15").val().indexOf("Other") != -1) {$("#CompanyTypeOther").fadeIn();}
	});
	*/
	
	$("#register_member_form").validate();
	$("#member_login_form").validate();
	
	$('.datesort').toggle(function() {
	  	$('.datesort').addClass('up');
		currentSort = "asc";
		loadList();
	}, function() {
	  	$('.datesort').removeClass('up');
		currentSort = "desc";
		loadList();
	});
	

	function filterChecked() {
		currentChecked = "";
		currentOffset = "0";
		if (($("#filter .insurance:checked").length) == 1){currentChecked += "1-"}
		if (($("#filter .securities:checked").length) == 1){currentChecked += "2-"}
		if (($("#filter .ft:checked").length) == 1){currentChecked += "3-"}
		if (($("#filter .asset:checked").length) == 1){currentChecked += "4-"}
		if (($("#filter .broker:checked").length) == 1){currentChecked += "5-"}
		if (($("#filter .pe:checked").length) == 1){currentChecked += "6-"}
		if (($("#filter .specialty:checked").length) == 1){currentChecked += "7-"}
		if (($("#filter .investment:checked").length) == 1){currentChecked += "12-"}
		
		if (currentChecked == ""){currentChecked = " ";}
		loadList();
	}
	
	function filterMediaChecked() {
		currentMediaChecked = "";
		currentOffset = "0";

		if (($("#filter .bloomberg:checked").length) == 1){currentMediaChecked += "8-"}
		if (($("#filter .financialtimes:checked").length) == 1){currentMediaChecked += "9-"}
		if (($("#filter .reuters:checked").length) == 1){currentMediaChecked += "10-"}
		if (($("#filter .financialnews:checked").length) == 1){currentMediaChecked += "11-"}

		if (currentMediaChecked == ""){currentMediaChecked = " ";}
		loadMediaList();
	}
	
	function loadList(){
		$('#sortstatus').html('<img src="/img/ajax-loader.gif" />');
		/*
		$('#PublicationsList').load("/publications/list/"+currentSort+"/"+currentChecked+"/"+currentOffset+"/"+currentSearch, function(){
			$("#PublicationsList").slideToggle(2500);
			$(".page").click(function(){ 
				var value = $(this).attr('id')+""; 
				value = value.replace("page", "");
				currentOffset=(value-1)*10; loadList();
			});
		});
		*/
		
		
		$.ajax({
		  url: "/publications/list/"+currentSort+"/"+currentChecked+"/"+currentOffset+"/"+currentSearch,
		  success: function(data) {

			$('#sortstatus').html('');
			$("#PublicationsList").html(data).fadeIn();
			$(".page").click(function(){ 
				var value = $(this).attr('id')+""; 
				value = value.replace("page", "");
				currentOffset=(value-1)*10; loadList();
			});
			$('#modal_login').jqm({toTop: true});
			$('a.trigger_login').click(function() { 
				$('#modal_login').jqmShow(); 
				$('html,body').animate({scrollTop: 0}, 0);
			});
		  }
		});
	}
	
	function loadMediaList(){
		$('#sortstatus').html('<img src="/img/ajax-loader.gif" />');
		/*
		$('#PublicationsList').load("/publications/list/"+currentSort+"/"+currentChecked+"/"+currentOffset+"/"+currentSearch, function(){
			$("#PublicationsList").slideToggle(2500);
			$(".page").click(function(){ 
				var value = $(this).attr('id')+""; 
				value = value.replace("page", "");
				currentOffset=(value-1)*10; loadList();
			});
		});
		*/
		
		$.ajax({ 
		  url: "/media-coverage/list/"+currentSort+"/"+currentMediaChecked+"/"+currentOffset+"/"+currentSearch,
		  success: function(data) {
		 
			$('#sortstatus').html('');
			$("#MediaList").html(data).fadeIn();
			$(".page").click(function(){ 
				var value = $(this).attr('id')+""; 
				value = value.replace("page", "");
				currentOffset=(value-1)*10; loadMediaList();
			});
			$('#modal_login').jqm({toTop: true});
			$('a.trigger_login').click(function() { 
				$('#modal_login').jqmShow(); 
				$('html,body').animate({scrollTop: 0}, 0);
			});
		  }
		});
	}
	
	currentSort = "desc";
	currentOffset = "0";
	currentChecked = "1-2-3-4-5-6-7-12";
	currentMediaChecked = "8-9-10-11";
	currentSearch = "";
	selectAll();
	
	$("#filter input").click(function(){ filterChecked(); });
	$("#filter input").click(function(){ filterMediaChecked(); });
	
	$("#filter .all").click(function(){ selectAll(); });
	$("#filter .removeall").click(function(){ removeAll(); });
	
	function selectAll(){
		$("#filter .removeallrow").show();
		$("#filter .selectallrow").hide();
		$('#filter input').attr('checked', true);
		filterChecked();
		filterMediaChecked(); 
	}
	
	function removeAll(){
		$("#filter .removeallrow").hide();
		$("#filter .selectallrow").show();
		$('#filter input').attr('checked', false);
		filterChecked();
		filterMediaChecked(); 
	}
	
	$('input[name="search-pub"]').live('focusout keyup', function(e) {
		var $this = $(this);
		searchterms = this.value.toLowerCase();
		searchtermsnospaces = searchterms; 
		searchtermsnospaces = searchtermsnospaces.replace(/^\s+|\s+$/g, '');
		searchtermsnospaces = searchtermsnospaces.replace(/ /g, "-");
		if(searchterms.length > 0 && searchterms != 'Enter keywords or phrases') {
			currentSearch = searchtermsnospaces;
			currentOffset = "0";
			selectAll();
			loadList();
		} else {
			$this.css('background', '#fff');
			currentSearch = "";
			loadList();
		}

	});
	
});

$(document).ready(function() {
	$('a.openDialog').toggle(function() {
			$("div#filter").show(); 
		}, function() {
			$("div#filter").hide(); 
	});
	
	$('div#image').wrap('<div id="imagebg" />');
			
	$(".tab_content").hide(); //Hide all content
	//	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	//	$(".tab_content:first").show(); //Show first tab content

		$("ul.tabs li#ulFirst").addClass("active").show(); //Activate first tab
		$("#tab-1").show(); //Show first tab content
		
		var pathname = window.location.href;
		
		var hashnum = strrpos(pathname, '#');
		if (hashnum != false){
			var ajaxname = pathname.substr(hashnum+1);
		}else{
			var ajaxname = false;
		} 
		if (ajaxname == 'login'){
			$("ul.tabs li").removeClass("active"); //Remove any "active" class
			$(".tab_content").hide(); //Hide all tab content
			$("ul.tabs li#ulLast").addClass("active").show(); //Activate first tab
			$("#tab-2").show(); //Show first tab content
		}
		
		$(".signuplink").click(function() {
			$("ul.tabs li").removeClass("active"); //Remove any "active" class
			$(".tab_content").hide(); //Hide all tab content
			$("ul.tabs li#ulFirst").addClass("active").show(); //Activate first tab
			$("#tab-1").show(); //Show first tab content
		});
		

		//On Click Event
		$("ul.tabs li").click(function() {

			$("ul.tabs li").removeClass("active"); //Remove any "active" class
			$(this).addClass("active"); //Add "active" class to selected tab
			$(".tab_content").hide(); //Hide all tab content

			var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
			$(activeTab).show(); //show the active ID content
			
			return false;
		});
		
		if($('label.email').hasClass('error')) { 
			$('.valid').show(); 
		};
		if($('label.confirmEmail').hasClass('error')) { 
			$('.email-match').show(); 
		};
		if($('label.confirmPassword').hasClass('error')) { 
			$('.password-match').show(); 
		};
		if($('label.email-login').hasClass('error')) { 
			$('.login-error').show(); 
		};
		
		$("#map1").gMap({ markers: [{ latitude: 40.758812,
		                              longitude: -73.975904, 
									  icon: { image: "/img/mapmarker.gif",
									          iconsize: [35, 53],
									          iconanchor: [17,52],
									          infowindowanchor: [12, 0] } }],
									          zoom: 15 });
									
		$("#map2").gMap({ markers: [{ latitude: 51.513203,
										longitude: -0.088427,
										icon: { image: "/img/mapmarker.gif",
		                                      iconsize: [35, 53],
		                                      iconanchor: [17,52],
		                                      infowindowanchor: [12, 0] } }],
											  zoom: 15 });
		
		
		$('#modal_login').jqm({trigger: 'a.trigger_login', toTop: true});
		$('a.trigger_login').click(function() { 
			$('#modal_signup').jqmHide(); 
			$('html,body').animate({scrollTop: 0}, 0);
			
		});
		
		/*$('#modal_signup').jqm({trigger: 'a.trigger_signup', toTop: true});
		$('a.trigger_signup').click(function() { 
			$('#modal_login').jqmHide(); 
			$('html,body').animate({scrollTop: 0}, 0);

		});*/
		
		$('a#trigger_signup').click(function() { 
			$('input#name').focus();
		});
		
		$("div#image").hide().bind("load", function () { $(this).show();  }).fadeIn(500);
		
});
