/* 
 * GLOBAL TOOLS AND UTILITIES
 * Place all custom scripts here.
 *
 */
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-\\

/* MAKE IT SAFE TO USE console.log ALWAYS */
window.log = function(){
    log.history = log.history || [];
    log.history.push(arguments);
    arguments.callee = arguments.callee.caller;
    if (this.console) 
        console.log(Array.prototype.slice.call(arguments));
};

(function(b){
    function c(){
    }
    for (var d = "assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","), a; a = d.pop();) 
        b[a] = b[a] || c;
});
(window.console = window.console || {});
(function($){
    // Insert ALL script below *****
	
	if($('#home_slider')[0]){
		$('#home_slider').anythingSlider({
			width     			: '964px',      
			height 	  			: '395px',
			delay               : 6000,
			animationTime       : 500,
			easing              : 'swing',
			autoPlayLocked  	: true,
			resumeDelay     	: 6000,
			pauseOnHover        : false, 
			stopAtEnd 			: false,
			hashTags            : false
		});
	}
	
	if($('#team_slider')[0]){
		$('#team_slider').anythingSlider({
			width     			: '333px',      
			height 	  			: '100px',
			delay               : 6000,
			animationTime       : 500,
			easing              : 'swing',
			autoPlayLocked  	: true,
			resumeDelay     	: 6000,
			pauseOnHover        : false, 
			stopAtEnd 			: false,
			hashTags            : false,
			buildNavigation		: false
		});
	}
	
	if($('#testi_slider')[0]){
		
		$('#testi_slider li').each(function(i){
			$(this).find('p:first').html($('.testi-block:eq('+i+') p:first').html())
			var getOfficerInPage = $('#offcer_name').text().toUpperCase();
			var testiOfficer = $(this).find('.loan_officer').text().toUpperCase();
			if(getOfficerInPage == testiOfficer){
				$(this).closest('li').removeClass('none');
			}
			else{
				$(this).remove();
			}
		});
		
		$('#testi_slider .testi-block').remove();
		
		// Testimonial remove on main template
		$('.templt_testCont').remove();
		if($('#testi_slider li').length > 1){
			$('#testi_slider').anythingSlider({
				width     			: '618px',      
				height 	  			: '112px',
				animationTime       : 500,
				easing              : 'swing',
				autoPlayLocked  	: false,
				pauseOnHover        : false, 
				stopAtEnd 			: false,
				hashTags            : false,
				buildNavigation		: false
			});
		}
		else{
			$('.testi-cont ul#testi_slider').css('position','static')	;
		}
	}
	
	
	
	$('#category-w-230').sSelect();	
	$('#category-w-101').sSelect({ ddMaxHeight : '200px' });
	$('#CAT_Category').sSelect();
	$('#CAT_FAQSortBy').sSelect();
	
	$('#contact_btn a, .contact-us-btn').colorbox({width:"761px", inline:true, href:"#contact_lightbox"},function(){
																							//Cufon.refresh();
																							Cufon.replace('.lightbox-cont h1, .lightbox-toplinks .g-prequalified, .lightbox-toplinks .contact-us-btn, .lightbox-cont2 h1', { fontFamily: 'Helvetica LT Condensed'});	
																						});
	
	$('#mortgageRate_btn a, #mort_btn_sde').colorbox({width:"1100px", inline:true, href:"#mortgageRate_lightbox"},function(){
																										//Cufon.refresh();
																										Cufon.replace('.lightbox-cont h1, .lightbox-toplinks .g-prequalified, .lightbox-toplinks .contact-us-btn, .lightbox-cont2 h1', { fontFamily: 'Helvetica LT Condensed'});	
																			document.getElementById('mortgage_iframe').src = "http://www.escapesomewhere.com/mortgageinterestrates.html";

																									});
																									
	$('a.mortgage-calculator').colorbox({width:"761px", inline:true, href:"#mortCalc"},function(){
																							//Cufon.refresh();
																							Cufon.replace('.lightbox-cont h1, .lightbox-toplinks .g-prequalified, .lightbox-toplinks .contact-us-btn, .lightbox-cont2 h1', { fontFamily: 'Helvetica LT Condensed'});	
																						});
	

	// home accordion
	if($('#home_accord')[0]){
		lastBlock = $("#a1");
		maxWidth = 450;
		minWidth = 258;	
	
		// for click
		$("ul li .accord_cont").click(
		  function(){
			$(lastBlock).animate({width: minWidth+"px"}, { queue:false, duration:400 });
			$(this).animate({width: maxWidth+"px"}, { queue:false, duration:400});
			lastBlock = this;
		  }
		);
		
		// for page load
		$(lastBlock).animate({width: minWidth+"px"}, { queue:false, duration:400 });
		$("ul li .accord_cont:first").animate({width: maxWidth+"px"}, { queue:false, duration:400});
	}
	
	// page tabbing
	if($('.tab-cont')[0]){
		$(".tab_content").hide(); //Hide all content
		$("ul.tabs li:first").addClass("selected").show(); //Activate first tab
		$(".tab_content:first").show(); //Show first tab content
		
		//On Click Event
		$("ul.lp-tabs li").click(function() {
			$("ul.lp-tabs li").removeClass("selected"); //Remove any "active" class
			$(this).addClass("selected"); //Add "active" class to selected tab
			$(".tab_content").hide(); //Hide all tab content
			var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
			$(activeTab).fadeIn(); //Fade in the active content
			return false;
		});
	}
	
	// set breadcrumbs
	if($('#catblogoutput')[0]){
		if($('.blog-post')[0]){
			$('.breadcrumbs-cont').html('<a href="/">Home</a><a href="/about">About</a><a href="/_blog/Mortgage_News" >Mortgage News</a><a href="'+document.location.pathname+'">'+$('h2.post-title').text()+'</a><div class="clr"></div>');
		}
		else{
			$('.breadcrumbs-cont').html('<a href="/">Home</a><a href="/about">About</a><a href="'+document.location.pathname+'" >Mortgage News</a><div class="clr"></div>');
		}
	}
	if($('.inner-content  .green-cont')[0]){
		$('.breadcrumbs-cont').html('<a href="/">Home</a><a href="/about">About</a><a href="/about/meet-our-loan-officers">Meet Our Loan Officers</a><a href="'+document.location.pathname+'">'+$('#offcer_name').text()+'</a><div class="clr"></div>');
	}
	if($('.faq_detail')[0]){
		$('.breadcrumbs-cont').html('<a href="/">Home</a><a href="/mortgage-resources">Mortgage Resources</a><a href="/mortgage-resources/faqs">FAQs</a><a href="'+document.location.pathname+'">'+$('#faq_title').html()+'</a>')
	}
	
	// breadcrumbs selected
	if($('.breadcrumbs-cont a')[0]){
		$('.breadcrumbs-cont a:last').addClass('selected');
	}
	
	// logo animation
	$('a.site_by').hover(function(){
		$(this).find('img:first').fadeOut(300);
	},function(){
		$(this).find('img:first').fadeIn(300);
	});
	
	// Loan Overview Video
	if($('#nav_1281313 > li:eq(0)').hasClass('selected')){
		$('.video-img .vid_lo').show();
	}
	else if($('#nav_1281313 > li:eq(1)').hasClass('selected')){
		$('.video-img .vid_pml').show();
	}
	else if($('#nav_1281313 > li:eq(2)').hasClass('selected')){
		$('.video-img .vid_r').show();
	}
	else if($('#nav_1281313 > li:eq(3)').hasClass('selected')){
		$('.video-img .vid_cl').show();
	}
	else if($('#nav_1281313 > li:eq(4)').hasClass('selected')){
		$('.video-img .vid_rm').show();
	}
	else if($('#nav_1281313 > li:eq(5)').hasClass('selected')){
		$('.video-img .vid_heloc').show();
	}
	
	// FAQ
	if($('.faqresultstable')[0]){
		$('.faqresultstablequestion').each(function(){
			$(this).append('<div class="faq-ans none"></div>');
		});
	}
	// FAQ drop down
	$('.faqresultstablequestion a').click(function(e){
			$('.faq-ans').slideUp(100).html('').addClass('none');
			var aSrc = $(this).attr('href');
			$(this).closest('td').find('.faq-ans').load(aSrc+" #faq_detail").slideDown(300).removeClass('none');
			e.preventDefault();
	})
	
	
	//SubMENU
	$('.subnav-cont.snc3 ul > li').mouseover(function(){
		if($(this).find('ul').length > 0 ){
			$('.subnav-cont.snc3 li ul').hide().css('zIndex','5');
			$(this).find('ul').show().css('zIndex','10');
		}
	}).mouseout(function(){
		$(this).find('ul').hide().css('zIndex','5');
		$('.subnav-cont.snc3 li.selected').find('ul').show().css('zIndex','10');
	});

	
	// *****************************    
})(jQuery);

var engine = {
		utils : {
			checkSelectorIfExist : function(a){
				if($(a).length > 0){
					return true;
				}else{
					return false;
				}
			}
		},
		blog : {
			blogPostLayout_Chooser : function(param){
				var readMoreLink = "";
				switch(param){
					case 1 :
						var a = $('.blog-list-homepage'), b = $('.blog-home-layout');
						a.find('.blog-tags-container').each(function(i, elem){
							$('.blog-post-body-preview').eq(i).find('a').each(function(){
								if($.trim($(this).text()) == "(read more)"){
									readMoreLink = '(<a href="'+$(this).attr('href')+'">read more</a>)';
								}
							});
							b.show();
							b.find('.bhl-post-title').eq(i).html($.trim($(this).find('.blog-post-title').html()));
							b.find('.bhl-post-body').eq(i).html($(this).find('.blog-post-body-preview').text().substr(0,100) + "... " + readMoreLink);
							$('.inner-section').eq(0).addClass('first');				
						});
					break;
					case 2 : 
						$('.blog-tags-container').each(function(i,elem){
							$('.blog-post-body-preview').eq(i).find('a').each(function(){
								if($.trim($(this).text()) == "(read more)"){
									readMoreLink = '(<a style="color: #159949 !important;" class="overall-read-morelink" href="'+$(this).attr('href')+'">read more</a>)';
								}
							});
							$('.bb-post-title').eq(i).html($(this).find('.blog-post-title').html());
							$('.bbl-post-body').eq(i).html($(this).find('.blog-post-body-preview').text().substr(0,100) + "... " + readMoreLink);
						});
						$('.blog-blog-list').show();
					break;
				}
			}
		}
}


