/* Author: Chase Foster of 303 Software */
// == Start Navigation JS



$("#navigation > ul > li > a,#navigation > ul > li > span").bind('mouseover',function(){
	if($(":animated").size() == 0)
	{
		// Global nav
		$(this).parent().siblings().children('a,span').css('color','#454F4F').filter('.blue').css('color','#005581');
		
		// Exception for contact us.
		if($(this).text() == 'CONTACT US' || $(this).text() == 'MY ACCOUNT')
		{
			//Contact us
			$(this).css('color','#F47735').parent().siblings().find('ul').hide(1,function(){$(this).parent().animate({marginTop: '55px'},200);});
		}
		else
		{
			// Standard Nav animation
			newMargin = 47 - ((parseInt($(this).parent().find('ul li').size()) * 15) / 2);

			
			$(this).css('color','#F47735').parent().animate({marginTop: newMargin + 'px'}).find('ul').slideDown().parent().siblings().find('ul').hide(1,function(){$(this).parent().animate({marginTop: '55px'},200);});
		}
		Cufon.replace('#navigation > ul > li > a,#navigation > ul > li > span' , { fontFamily: 'Amasis',fontWeight: 700,hover: true }); 
	}
}); 
// Activate hover for contact us execption
$('.contactus a').bind('mouseleave',function(){
	$(this).css('color','#454F4F');
	Cufon.replace('#navigation > ul > li > a' , { fontFamily: 'Amasis',fontWeight: 700,hover: true }); 
	
});
$('.myaccount a').bind('mouseleave',function(){
	$(this).css('color','#005581');
	Cufon.replace('#navigation > ul > li > a' , { fontFamily: 'Amasis',fontWeight: 700,hover: true }); 
});
$('#navigation').bind('mouseleave',function(){
	if($(":animated").size() == 0){
		// == Not animating. Reset Nav after 1 sec.
		clearTimeout(t);
		var hideDelay = 1000;
		var t = setTimeout("$('#navigation > ul > li').children('a,span').css('color','#454F4F').filter('.blue').css('color','#005581');$('#navigation > ul > li').animate({marginTop: '55px'}).find('ul').hide();Cufon.replace('#navigation > ul > li > a,#navigation > ul > li > span' , { fontFamily: 'Amasis',fontWeight: 700,hover: true  }); ",hideDelay);
 	}
 	else{
 		// == If animating. Wait longer so that the animations don't conflict.
 		clearTimeout(t);
		var hideDelay = 2000;
		var t = setTimeout("$('#navigation > ul > li').children('a,span').css('color','#454F4F').filter('.blue').css('color','#005581');$('#navigation > ul > li').animate({marginTop: '55px'}).find('ul').hide();Cufon.replace('#navigation > ul > li > a,#navigation > ul > li > span' , { fontFamily: 'Amasis',fontWeight: 700,hover: true  }); ",hideDelay);
 	}	
});
// == End Navigation JS

// == Start font replacement

Cufon.replace('#navigation > ul > li > a,#navigation > ul > li > span' , { fontFamily: 'Amasis',fontWeight: 700,hover: true  }); 
Cufon.replace('#navigation > ul > li > ul > li > a' , { fontFamily: 'Amasis',fontWeight: 500,hover: true  }); 
Cufon.replace('#login-panel ul li a' , { fontFamily: 'Amasis',fontWeight: 700,hover: true  }); 
Cufon.replace('.home-panel h1' , { fontFamily: 'Amasis',fontWeight: 700,hover: true }); 
Cufon.replace('.panel-footer a' , { fontFamily: 'Amasis',fontWeight: 700,hover: true  }); 
Cufon.replace('#footer-nav a' , { fontFamily: 'Amasis',fontWeight: 700,hover: true  });
//Cufon.replace('#content > li, #content > p' ,{ ignoreclass : 'nocufon', fontFamily: 'Amasis',fontWeight: 500,hover: true  });
Cufon.replace('#side-nav h1' , { fontFamily: 'Amasis',fontWeight: 500,hover: true  });
Cufon.replace('#side-nav li,#side-nav-account li' , { fontFamily: 'Amasis',fontWeight: 500,hover: true  });
Cufon.replace('.orange-block' , { fontFamily: 'Amasis',fontWeight: 700,hover: true  });
Cufon.replace('#content .email-footer' , { fontFamily: 'Amasis',fontWeight: 700,hover: true  });
Cufon.replace('.whitepage-footer > a' , { fontFamily: 'Amasis',fontWeight: 700,hover: true  });
Cufon.replace('.input-submit' , { fontFamily: 'Amasis',fontWeight: 700,hover: true  });
Cufon.replace('#content .bio-title h2 ' , { fontFamily: 'Amasis',fontWeight: 500,hover: true  });
Cufon.replace('#content .bio-description span.orange' , { fontFamily: 'Amasis',fontWeight: 500,hover: true  });
Cufon.replace('#content-account h2' , {  ignoreclass : 'nocufon', fontFamily: 'Amasis',fontWeight: 700 }); 
Cufon.replace('#content-account' , {  fontFamily: 'Amasis',fontWeight: 500,hover: true });
Cufon.replace('html.js body div#container div#main div#content-head.section-resources div#center-layout div#content div h2' , {  fontFamily: 'Amasis',fontWeight: 500});  
Cufon.replace('#content > div.resource-item > h2' , {  ignoreclass : 'nocufon', fontFamily: 'Amasis',fontWeight: 700 }); 
Cufon.replace('#content > div.whitepaper > h2' , {  ignoreclass : 'nocufon', fontFamily: 'Amasis',fontWeight: 500}); 
Cufon.replace('#content > h2' , {  ignoreclass : 'nocufon', fontFamily: 'Amasis',fontWeight: 700}); 
Cufon.replace('#content > div > h2' , {  ignoreclass : 'nocufon', fontFamily: 'Amasis',fontWeight: 700});
Cufon.replace('.synopsis-intro' , {  ignoreclass : 'nocufon', fontFamily: 'Amasis',fontWeight: 500,hover:true });

// == End font replacement

// == Start Slider
// Init Slider
$('#active-slide').removeClass().addClass($("#home-slides > ul > li:first").attr('class'));
$('#breadcrumbs li:first').css('background-color', '#F47735');
$('#active-slide').html($('#slides li:first').html());
Cufon.replace('#slides > li > h3' , { fontFamily: 'Amasis',fontWeight: 700});
Cufon.replace('#active-slide > div > h3' , { fontFamily: 'Amasis',fontWeight: 700});
Cufon.replace('#active-slide > div > p' , { fontFamily: 'Amasis',fontWeight: 500});
// Set labels
$('#slides > li:first').css('background-position','0px 0px');
// Main Slide label triggers
$('#slides > li').bind('mouseover',function(){
	$(this).css('background-position','0px 0px').siblings().css('background-position','0px -60px');
	var hoverIndex = $(this).index();
	var newTop = 55 + (60 *(hoverIndex));
	$('#slide-mask').stop().animate({top: newTop + 'px' });
	var classClicked = $(this).attr('class');
	$('#active-slide').html($('#slides li').filter('.' + classClicked).html());
	$("#prev-slide").removeClass().addClass($('#active-slide').attr('class')).parent().find('#active-slide').hide().removeClass().addClass(classClicked).fadeIn();;
	$('#breadcrumbs > li').css('background-color','#ccc').filter('.' + classClicked).css('background-color','#F47735');
	// == 
	Cufon.replace('#active-slide > div > h3' , { fontFamily: 'Amasis',fontWeight: 700});
	Cufon.replace('#active-slide > div > p' , { fontFamily: 'Amasis',fontWeight: 500});
});
// 
$('#breadcrumbs > li').bind('mouseenter',function(){
	var hoverIndex = $(this).index();
	var newTop = 55 + (60 *(hoverIndex));
	$('#slide-mask').stop().animate({top: newTop + 'px' });
	var classClicked = $(this).attr('class');
	$('#slides > li').css('background-position','0px -60px').filter('.' + classClicked).css('background-position','0px 0px');
	$('#active-slide').html($('#slides li').filter('.' + classClicked).html());
	$("#prev-slide").removeClass().addClass($('#active-slide').attr('class')).parent().find('#active-slide').hide().removeClass().addClass(classClicked).fadeIn();;
	$('#breadcrumbs > li').css('background-color','#ccc').filter('.' + classClicked).css('background-color','#F47735');
	// == 
	Cufon.replace('#active-slide > div > h3' , { fontFamily: 'Amasis',fontWeight: 700});
	Cufon.replace('#active-slide > div > p' , { fontFamily: 'Amasis',fontWeight: 500});
});
// for each li add it to the breadcrumbs

// Set min-height for #content to fit window
var winheight = window.innerHeight - 313;
if($("#content").size() != 0){
	var theheight = parseInt($("#content").css('height'));
	if(theheight < winheight){ 
		$("#content").css('height', winheight +'px');
		$("#side-nav-account").css('height', (winheight + 46) +'px');
		
	}
	else
	{
		$("#side-nav-account").css('height', (theheight + 46) +'px');
		$(".dotted-line").css('height', (theheight) +'px');
	}
}
else 
{
var theheight = parseInt($("#content-account").css('height') + 14);
	if(theheight < winheight){ 	
		if (theheight > 313){
		}else{
		$("#content-account").css('height', winheight +'px');
		$("#side-nav-account").css('height', (winheight + 46) +'px');
		$("#side-nav").css('height', (winheight + 46) +'px');
		$(".dotted-line").css('height', (winheight) +'px');
		}
	}
	else
	{
		$("#content-account").css('height', (theheight + 180) +'px');
		$("#side-nav-account").css('height', (theheight + 46) +'px');
		$("#side-nav").css('height', (winheight + 46) +'px');
		$(".dotted-line").css('height', (theheight) +'px');
	}
}


	
	


//$('#breadcrumbs').html('<ul></ul>');
// Click Slider
/*$('#home-slides > ul > li').bind('mouseup',function(){
	var initialTop = parseInt($('#slide-mask').css('top'));
	var hoverIndex = parseInt($(this).index());
	var newTop = 55 + (60 *(hoverIndex));
	var classClicked = $(this).attr('class');
	// Move active class to prev class.
	//if(initialTop != newTop )
	//{
		//$('#slide-mask').animate({top: newTop + 'px' });
		//var classClicked = $(this).attr('class');
		// Move active class to prev class.
		$("#prev-slide").removeClass().addClass($('#active-slide').attr('class')).parent().find('#active-slide').hide().removeClass().addClass(classClicked).fadeIn();
	//}
});*/
/*$('#home-slides > ul > li').bind('mouseenter',function(){
	//if($(":animated").size() == 0){
		//var initialTop = parseInt($('#slide-mask').css('top'));
		//var hoverIndex = parseInt($(this).index());
		//var newTop = 55 + (60 *(hoverIndex));
		//var classClicked = $(this).attr('class');
		
		//if(initialTop != newTop )
		//{
			//$('#slide-mask').animate({top: newTop + 'px' });
			
			$('#breadcrumbs > li').css('background-color','#ccc').filter('.' + classClicked).css('background-color','#F47735');
			//$(this).css('background-color','#F47735').siblings().css('background-color','#ccc');
			
			var classClicked = $(this).attr('class');
			// Move active class to prev class.

		//}
	//}
});*/
// == End Slider
// Image preloader
function preload(arrayOfImages) {
    $(arrayOfImages).each(function(){
        $('<img/>')[0].src = this;
    });
}
// Create pdf over ajax
$('.pdf').click(function(e){
	// Load data
	e.preventDefault();
	var htmldata = $('#pdfdata').html();
	//create the form and submit it
	$('#htmldata').val(htmldata).parent().submit();
	//$('form#frmpdf').submit();
});

$("#sendadvisor").fancybox({
	'titlePosition'		: 'inside',
	'transitionIn'		: 'none',
	'transitionOut'		: 'none',
	'overlayColor' : "#000"
});
			
$('.1sendemail').click(function() {
   $.ajax({
   type: "POST",
   url: "../email",
	dataType : 'json',
	data: {
	yourname : $('#shareyourname').val(),
	youremail : $('#shareyouremail').val(),
	youradvisorname : $('#shareyouradvisorname').val(),
	youradvisoremail : $('#shareyouradvisoremail').val(),
	comments : $('textarea[name="sharecomments"]').val(),
	resourcebody : $('#resourcebody').val()
	},
   success : function(data){
		if(data.error === true){
		$('.successerror').html('Error').css('color','red');
		}else{
		$('.successerror').html('Email Sent!').css('color','green');
		$('.sendemail').html('Email Sent!').css('display','none');
		}
		
	},
	error : function(data) {
		$('.successerror').html('Error').css('color','red');
	}
	
	});
  return false;
});

// validate signup form on keyup and submitW
$("#advisorform").validate({
rules: {
shareyourname: "required",
shareyouradvisorname: "required",
shareyouradvisoremail: {
required: true,
email: true
},
shareyouremail: {
required: true,
email: true
}
},
submitHandler: function(form) {
   $.ajax({
   type: "POST",
   url: "../email",
	dataType : 'json',
	data: {
	yourname : $('#shareyourname').val(),
	youremail : $('#shareyouremail').val(),
	youradvisorname : $('#shareyouradvisorname').val(),
	youradvisoremail : $('#shareyouradvisoremail').val(),
	comments : $('textarea[name="sharecomments"]').val(),
	resourcebody : $('#resourcebody').val()
	},
   success : function(data){
		if(data.error === true){
		$('.successerror').html('Error').css('color','red');
		}else{
		$('.successerror').html('Email Sent!').css('color','green');
		$('.sendemail').html('Email Sent!').css('display','none');
		}
		
	},
	error : function(data) {
		$('.successerror').html('Error').css('color','red');
	}
	
	}); 
 }
}); 


