$(document).ready(function () {

// pop up announcement
	var announcement='<div id="announcement"><div class="left"><img src="/images/hdr-announcement.gif" alt="Cole & Partners acquired by Duff &amp; Phelps"></div>';
	announcement+='<div class="right"><p><strong>On June 15, 2010, Cole &amp; Partners became part of  Duff &amp; Phelps Corporation. Duff &amp; Phelps is a leading global independent provider of financial advisory and investment banking services supporting client needs principally in the areas of valuation, transactions, financial restructurings, dispute and taxation.</strong></p><p>The entire firm is joining Duff &amp; Phelps and is very enthusiastic about the transaction. The combination allows us to provide our clients with an expanded service offering, global scale and access to more than 1,000 professionals with deep technical and industry expertise. The fully integrated entity represents a combination of like-minded organizations, which are equally committed to high-quality service, independence and financial expertise.</p><p>Our clients will receive the same dedicated, high quality service and attention from us as they always have in the past. Our telephone numbers and location will not change as a result of this transaction.</p><p>Thank you for your continued support. We look forward to working with you in the years to come. <a href="/pdf/DP_Press_Release_Cole_Partners.pdf">View the press release</a> to learn more about this transaction and visit <a href="http://www.duffandphelps.com" target="_blank">www.duffandphelps.com</a> to learn more about Duff &amp; Phelps.</p></div><div class="clear"></div></div>';
	if(!readCookie('visited')){
		$.fancybox(
			announcement,
			{
				'autoDimensions'	: false,
				'width'         	: 810,
				'height'        	: 'auto',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'padding'			: 30,
				'hideOnOverlayClick': false,
				'onClosed'			: function(){createCookie('visited',true)}
			}
		);
	}
	
  	$('.fade .over').bind("mouseover", function() {
		$('.fade .over').stop().fadeTo(250, 0);
		var $this = $(this).stop().fadeTo(250, 1);
		if ($this.data("rolloutTimer")) clearTimeout($this.data("rolloutTimer"));
	});
	$('.fade .over').bind("mouseout", function() {
		$('.fade .over').stop().fadeTo(250, 0);
		var $this = $(this);
			$this.data("rolloutTimer", setTimeout(function() {
		}, 50));
	});

	jQuery.each(jQuery.browser, function(i) {
		if($.browser.msie && $.browser.version<7){
		}else{
			$('div.person').bind("mouseover", function() {
				$('div.person').stop().fadeTo(250, 0.4);
				var $this = $(this).stop().fadeTo(250, 1);
				if ($this.data("rolloutTimer")) clearTimeout($this.data("rolloutTimer"));
			});
			$('div.person').bind("mouseout", function() {
				$('div.person').stop().fadeTo(250, 1);
				var $this = $(this);
				$this.data("rolloutTimer", setTimeout(function() {
				}, 50));
			});
		}
	});



	$('#accordion h3').click(function() {
		var src = $(this).children().attr('src');
		$(this).next().toggle('blind');
		if(src.indexOf('closed.gif') != -1) {
			$(this).children().attr('src', src.replace(/closed.gif/,"open.gif"))
		} else {
			$(this).children().attr('src', src.replace(/open.gif/,"closed.gif"))
		}
		return false;
	});
	
	function expand(e) {
		var a = e;
		var b = a.attr('href');
		$('#'+b).show('blind',null,1000,function(){$(a).insertBefore('#'+b)});
		e.unbind('click');
		e.bind('click',function(e){
			e.preventDefault();
			hide($(this));
		});
	}
	function hide(e) {
		var a = e;
		var b = a.attr('href');
		$('#'+b).hide('blind',null,1000,function(){$(a).appendTo('.'+b)});
		e.unbind('click');
		e.bind('click',function(e){
			e.preventDefault();
			expand($(this));
		});
	}
	$('.expand').bind('click',function(e){
		e.preventDefault();
		expand($(this));
	});
	
	$('a.more-publications').click(function(e) {
		e.preventDefault();
		var id = $(this).attr('href');
		$("#"+id).toggle('blind');
		return false;
	});

	$('#services #tabs img').bind('click',function(e){
		var name=$(this).attr('name');
		$('.container').css('display','none');
		
		$('#'+name).css('display','block');
		$('#services #tabs img').each(function() {
			var src = $(this).attr('src');
			if(src.indexOf("-on.gif")==-1){
				$(this).attr('src',src.replace("-off.gif","-on.gif"));
			} else {
				$(this).attr('src',src.replace("-on.gif","-off.gif"));
			}
		});
	});

	
	$('#subscribe-form').bind('submit', function(e){
		e.preventDefault();
		var em = $(this).children("input[name='email']");
		var btn = $(this).children("input[name='button']");
		//var filter = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9-])+\.+[a-zA-Z0-9]{2,4}+$/;
		var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (!filter.test(em.attr('value'))) {
			alert('Please enter a valid email address');
		} else {
			em.attr("readonly","true");
			btn.attr("disabled","true");
			$.post('/includes/email.php', {email: em.attr('value')}, function(data, textStatus){
				if(textStatus=='success'){
					em.attr("value",data);
				} else {
					em.attr("readonly","false");
					btn.attr("disabled","false");
				}
			});
		}
	});
	$('#subscribe-form .text').bind('focus', function(e){
		if($(this).attr("value")=="Thank you!"){
		} else {
			$(this).attr("value","");
		}
	});
	$('#subscribe-form .text').bind('blur', function(e){
		if($(this).attr("value")==""){
			$(this).attr("value","Enter your email address");
		}
	});
});

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
