$(function() {
	
	
	Cufon.replace('h5.subtitle , h5.expert-title, div#expert-extended p',{ hover: true });
	
	
	var e = 'div.modal-window';
	var g = $(e).outerHeight();
	var y = $('body').height();
	
	$(e).css({top: -g});
	
	$('a.showModal').click(function(){
		
		var thisHref = $(this).attr('hash');
		
		var f = $(e).outerWidth();
		var x = $(window).width();
		var z = ((x - f) + 80) / 2;
		$(e).css('left',z);
		
		$(thisHref).show(0,function(){
		
		$(this).animate({
			top: 0
		}, 400);
		
		});
		
		$('div#modal').css('height',y).fadeIn();
		
		return false;
	
	});
	
	$('div#modal , a.closeModal').click(function(){
	
		$(e).animate({
			top: -g
		}, 400, function(){ $(this).hide(); });
		
		$("#response , #error").empty();
		$('#mail-list').css('opacity','1');
		
		$('div#modal').fadeOut();
		
		return false;
	
	});
	

  
  //bind form using 'ajaxForm' 
  $('#mail-list').ajaxForm({  
    target:"#hidden-div", 
    beforeSubmit:function() {
       $('#mail-list').fadeTo(50,'.10', function(){ $("#loading").show(); });
    },
    success:function(response) {
      $("#loading").hide();
      if (response=="success") {
        $("#mail-list").fadeOut(200,0).resetForm();
        $("#response").html("Thank you for joining our mailing list.");
        
      } else {
        $('#mail-list').fadeTo(200,'1');
        $("#error").html(  $("#hidden-div #content ul").html() );
        $("#hidden-div , #response").empty(); 
      }
    }
  });
  
  
  // news archive select
  $('select#news-archives').change(function(){
  	var thisVal = $(this).val();
  	
  	if (thisVal) {
  		window.location = thisVal
  	};
  	
  });
  
  
  //transaction hover
  $('a.transaction').hover(
  	function () {
  		var x = $(this).attr('rel');
  		
  		$(this).addClass('hover');
  		$(this).children('span').show();
  		
  	}, 
  	function () {
  		$(this).children('span').hide(0,function(){
  			$(this).parents('a').removeClass('hover');
  		});
  	}
  );
  
  $('a.transaction').click(function(){ return false })
  
  // expert filter
/*  $('div.filter-options select').change(function(){
  
  	var loc = $('select#filterLocations').val();
  	var exp = $('select#filterExpertise').val();
  	var url = 'http://206.214.218.178/~caryst/'
  	var uri = 'index.php/meet-our-experts/filter/';
  	var results = 'div#filter-results span';
  	
  	$(results).html('<img src="' + url + '/ui/scripts/ajax-loader.gif" alt="Loading..." style="float:none;border:none;margin:0 0 30px;" />');
  	
  	$('#filter-instructions').hide();
  	
  	if ((loc && loc != "all") && exp) {
  		$(results).load(url + uri + loc + '&' + exp);
  	};
  	
  	if (loc == "all" && exp) {
  		$(results).load(url + uri + '7|8|9|10|11|' + exp);
  	};
  	
  	if (loc == "all" && exp == "") {
  		$(results).load(url + uri + '7|8|9|10|11');
  	};
  	
  	if ((loc && loc != "all") && exp == "") {
  		$(results).load(url + uri + loc);
  	};
  	
  	if (exp && loc == "") {
  		$(results).load(url + uri + exp);
  	};
  	
  	if (exp == "" && loc == "") {
  		$(results).html('');
  		$('#filter-instructions').show();
  	};
  
  });*/
  
  $('ul#expert-list li').hide();
  
  /*$('div.filter-options select').change(function(){
  	
  	var loc = $('select#filterLocations').val();
  	var exp = $('select#filterExpertise').val();
  	
  	if ((loc && exp == "") || (loc && exp == "all")) {
  		var results = loc;
  	};
  	
  	if (loc && exp) {
  		var results = loc + '.' + exp;
  	};
  	
  	if ((loc == "" && exp) || (loc == "all" && exp)) {
  		var results = exp;
  	};
  	
  	$('ul#expert-list li').hide();
  	if ($('ul#expert-list li.' + results).length != 0){
  		$('ul#expert-list li.' + results).fadeIn();
  		$('#no-results').hide();
  	} else {
  		$('#no-results').show();
  	};
  	
  	if (loc == "all" && exp == ""){
  		$('#no-results').hide();
  		$('ul#expert-list li').fadeIn();	
  	};
  	
  	$('p#filter-instructions').hide();
  	if (loc == "" && exp == ""){
  		$('p#filter-instructions').fadeIn();
  		$('#no-results').hide();
  	};
  	
  	
  });*/
  
  
  $('div.filter-options select').change(function(){
  	
  	var loc = $('select#filterLocations').val();
  	
  	$('ul#expert-list li').hide();
  	if (loc == "all"){
  		$('ul#expert-list li').fadeIn();
  		$('p#filter-instructions').hide();
  	} else if ($('ul#expert-list li.' + loc).length != 0){
  		$('ul#expert-list li.' + loc).fadeIn();
  		$('#no-results').hide();
  		$('p#filter-instructions').hide();
  	} else if (loc == 'none') {
  		$('p#filter-instructions').show();
  	} else {
  		$('#no-results').show();
  	};
  	
  	if (loc == 'none'){$('p#filter-instructions').show();}
  	
  });
  

});
