jQuery.noConflict();


/* Copyright (c) 2006 Mathias Bank (http://www.mathias-bank.de)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * 
 * Thanks to Hinnerk Ruemenapf - http://hinnerk.ruemenapf.de/ for bug reporting and fixing.
 */
jQuery.extend({
/**
* Returns get parameters.
*
* If the desired param does not exist, null will be returned
*
* @example value = $.getURLParam("paramName");
*/ 
 getURLParam: function(strParamName){
	  var strReturn = "";
	  var strHref = window.location.href;
	  var bFound=false;
	  
	  var cmpstring = strParamName + "=";
	  var cmplen = cmpstring.length;

	  if ( strHref.indexOf("?") > -1 ){
	    var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	    var aQueryString = strQueryString.split("&");
	    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	      if (aQueryString[iParam].substr(0,cmplen)==cmpstring){
	        var aParam = aQueryString[iParam].split("=");
	        strReturn = aParam[1];
	        bFound=true;
	        break;
	      }
	      
	    }
	  }
	  if (bFound==false) return null;
	  return strReturn;
	}
});




jQuery(document).ready(function($) {
$('.category-4').mouseenter(function() {
	$('.category-4 ul#meganav-links').show(300);
	return false;
});

$('.category-4').mouseleave(function() {
	$('.category-4 ul#meganav-links').hide(300);
	return false;
});


$('.category-5').mouseenter(function() {
	$('.category-5 ul#meganav-links').show(300);
	return false;
});

$('.category-5').mouseleave(function() {
	$('.category-5 ul#meganav-links').hide(300);
	return false;
});


$('.category-6').mouseenter(function() {
	$('.category-6 ul#meganav-links').show(300);
	return false;
});

$('.category-6').mouseleave(function() {
	$('.category-6 ul#meganav-links').hide(300);
	return false;
});


$('.category-7').mouseenter(function() {
	$('.category-7 ul#meganav-links').show(300);
	return false;
});

$('.category-7').mouseleave(function() {
	$('.category-7 ul#meganav-links').hide(300);
	return false;
});



	
	//$('body.safari div#footer_social a.rss').attr("href","feed://fearless.eroidev.com/feed/");

    // Search bar
	$("#search-on").hide();
	$("#search-off").click(function() {
		$("#search-on").show();
	});
	
	
	// hover links
	$("a#home-lesson-button").hover(
	  function () {
		$("a#home-lesson-button img").hide();
	  }, 
	  function () {
		$("a#home-lesson-button img").show();
	  }
	);
	
	$("div#search-off p").hover(
	  function () {
		$("div#search-off p img").hide();
	  }, 
	  function () {
		$("div#search-off p img").show();
	  }
	);
	
	$("div.lesson-center-link a").hover(
	  function () {
		$("div.lesson-center-link a img").hide();
	  }, 
	  function () {
		$("div.lesson-center-link a img").show();
	  }
	);
	
	$("div#home-video a").hover(
	  function () {
		$("div#home-video a img").hide();
	  }, 
	  function () {
		$("div#home-video a img").show();
	  }
	);
	
	$("div#home-lesson a").hover(
	  function () {
		$("div#home-lesson a img").hide();
	  }, 
	  function () {
		$("div#home-lesson a img").show();
	  }
	);
	
	$("div#buyers-link a").hover(
	  function () {
		$("div#buyers-link a img").hide();
	  }, 
	  function () {
		$("div#buyers-link a img").show();
	  }
	);
	
	$("a.sidebar_resouce_button").hover(
	  function () {
		$("a.sidebar_resouce_button img").hide();
	  }, 
	  function () {
		$("a.sidebar_resouce_button img").show();
	  }
	);
	
	$("div#footer_social a.twitter, div#share_social a.twitter").hover(
	  function () {
		$("div#footer_social a.twitter img, div#share_social a.twitter img").hide();
	  }, 
	  function () {
		$("div#footer_social a.twitter img, div#share_social a.twitter img").show();
	  }
	);
	
	$("div#footer_social a.facebook, div#share_social a.facebook").hover(
	  function () {
		$("div#footer_social a.facebook img, div#share_social a.facebook img").hide();
	  }, 
	  function () {
		$("div#footer_social a.facebook img, div#share_social a.facebook img").show();
	  }
	);
	
	$("div#footer_social a.rss, div#share_social a.rss").hover(
	  function () {
		$("div#footer_social a.rss img, div#share_social a.rss img").hide();
	  }, 
	  function () {
		$("div#footer_social a.rss img, div#share_social a.rss img").show();
	  }
	);
	
	$("div#footer_social a.youtube, div#share_social a.share-email").hover(
	  function () {
		$("div#footer_social a.youtube img, div#share_social a.share-email img").hide();
	  }, 
	  function () {
		$("div#footer_social a.youtube img, div#share_social a.share-email img").show();
	  }
	);
	
	$("a.button-agent-footer").hover(
	  function () {
		$("a.button-agent-footer img").hide();
	  }, 
	  function () {
		$("a.button-agent-footer img").show();
	  }
	);
	
	$("a.button-contact-footer").hover(
	  function () {
		$("a.button-contact-footer img").hide();
	  }, 
	  function () {
		$("a.button-contact-footer img").show();
	  }
	);
	
	$("div.previous-lesson a").hover(
	  function () {
		$("div.previous-lesson").addClass('previous-lesson-hover');
	  }, 
	  function () {
		$("div.previous-lesson").removeClass('previous-lesson-hover');
	  }
	);
	
	$("div.next-lesson a").hover(
	  function () {
		$("div.next-lesson").addClass('next-lesson-hover');
	  }, 
	  function () {
		$("div.next-lesson").removeClass('next-lesson-hover');
	  }
	);
	
	$("a.follow-twitter").hover(
	  function () {
		$("a.follow-twitter img").hide();
	  }, 
	  function () {
		$("a.follow-twitter img").show();
	  }
	);
	
	$("a.follow-facebook").hover(
	  function () {
		$("a.follow-facebook img").hide();
	  }, 
	  function () {
		$("a.follow-facebook img").show();
	  }
	);
	
	$("a.follow-linkedin").hover(
	  function () {
		$("a.follow-linkedin img").hide();
	  }, 
	  function () {
		$("a.follow-linkedin img").show();
	  }
	);
	
	$("a.contact-agent").hover(
	  function () {
		$("a.contact-agent img").hide();
	  }, 
	  function () {
		$("a.contact-agent img").show();
	  }
	);
	
	$("a.contact-lender").hover(
	  function () {
		$("a.contact-lender img").hide();
	  }, 
	  function () {
		$("a.contact-lender img").show();
	  }
	);
	
	$("div#search-results-form form input#searchsubmit, form#noresults-searchform input#noresults-searchsubmit").hover(
	  function () {
		$("div#search-results-form form input#searchsubmit, form#noresults-searchform input#noresults-searchsubmit").addClass('search-hover');
	  }, 
	  function () {
		$("div#search-results-form form input#searchsubmit, form#noresults-searchform input#noresults-searchsubmit").removeClass('search-hover');
	  }
	);
	
	$("form#newsletter input.submit").hover(
	  function () {
		$("form#newsletter input.submit").addClass('news-hover');
	  }, 
	  function () {
		$("form#newsletter input.submit").removeClass('news-hover');
	  }
	);
	
	
	$("input#submit-search").hover(
	  function () {
		$("input#submit-search").addClass('submit-search-hover');
	  }, 
	  function () {
		$("input#submit-search").removeClass('submit-search-hover');
	  }
	);
	
	
	//lender social
	$('div.agent-social').has('a.follow-twitter').show();
	$('div.agent-social').has('a.follow-facebook').show();
	$('div.agent-social').has('a.follow-linkedin').show();
	
	
	//state local area title
	if ($('li.state ul').is(':empty')) {
			$('li.state h3').hide();
	}
	
	// colorbox

	$(".video-example").colorbox({inline:true, href:"#youtube-video", innerWidth:480, innerHeight:385}); 
	$('#footer-agent').colorbox({inline:true, href:"#footer-agent-box", speed:600, width:'750px'});
	


	$('#choose-agent').colorbox({inline:true, href:"#choose-agent-box", speed:600, width:'750px'});
	$('#why-agent').colorbox({inline:true, href:"#why-agent-box", speed:600, width:'750px'});
	$('#become-agent').colorbox({inline:true, href:"#become-agent-box", speed:600, width:'750px'});
	$('.contact-agent').colorbox({inline:true, href:"#contact-agent-form", speed:600, width:'500px'});
	$('#contact-lender').colorbox({inline:true, href:"#contact-lender-form", speed:600, width:'750px'});
	$('#ask-question').colorbox({inline:true, href:"#ask-question-form", speed:600, width:'500px'});
	$('#local-info-contact').colorbox({inline:true, href:"#ask-question-form", speed:600, width:'750px'});
	$('#share-email').colorbox({inline:true, href:"#share-email-form", speed:600, width:'500px'});
	
	// lessons tab section
	var commentHash = document.location.toString().split('#comment')[1];
	
	if (commentHash) {
		$('#tabs').tabs({ selected: 2 });
	} else {
		$('#tabs').tabs();
	}
	//var finances = document.location.toString().split('#finances')[1];
	var beforeBuying = document.location.toString().split('#beforeBuying')[1];
	var duringBuying = document.location.toString().split('#duringBuying')[1];
	var afterBuying = document.location.toString().split('#afterBuying')[1];
	var finances = $.getURLParam("finances");
	var beforeBuying = $.getURLParam("beforeBuying");
	var duringBuying = $.getURLParam("duringBuying");
	var afterBuying = $.getURLParam("afterBuying");

	if ($.getURLParam("finances")=="true") {
		$("#chapter-accordion").accordion({header: "h3", autoHeight: false, active: 0 });
	} 
	else if ($.getURLParam("beforeBuying")=="true") {
		$("#chapter-accordion").accordion({header: "h3", autoHeight: false, active: 1 });
	} 
	else if ($.getURLParam("duringBuying")=="true") {
		$("#chapter-accordion").accordion({header: "h3", autoHeight: false, active: 2 });
	} 
	else if ($.getURLParam("afterBuying")=="true") {
		$("#chapter-accordion").accordion({header: "h3", autoHeight: false, active: 3 });
	} else {
		$("#chapter-accordion").accordion({header: "h3", autoHeight: false, active: 0 });
	}
	
	$('.chapter-tabs').tabs({event: 'mouseover' });


	//change list into dropdown
	 $('ul.selectdropdown').each(function() {
        var $select = $('<select />');

        $(this).find('a').each(function() {
            var $option = $('<option />');
            $option.attr('value', $(this).attr('href')).html($(this).html());
            $select.append($option);
        });

        $(this).replaceWith($select);
    });
				
	$('#fearless-sidebar-state select').change(function(){
		//var url = $(this).val();
		//$(window.location).attr('href', url);
		 window.location = $(this).val();
	});
	
	//lesson state drop down search
	$('select#search_state').selectmenu({
		style: 'dropdown',
		change: function () {
			$('#search_city-button').addClass('remove');
		}
	}); 
	
	$('select#search_city').selectmenu({style:'dropdown'});

	$('select[name="state"]').change(function(){
		if($(this).val() != ''){
			$.get('/?ajax=true&type=exception&state='+$(this).val()+'&exception_post_id='+$('input[name="exception_post_id"]').val(), function(data) {
				$('div.state-exception').html(data);
				$('#contact-us').colorbox({inline:true, href:"#contact-us-form", speed:600, width:'500px'});
			});
		}
	});
	
	$('select#search_state').change(function(){
            
		var selected_state = $('select#search_state').val();            
		$('select#search_city').load('/find-a-buyers-agent/?do=city_dropdown&state=' + selected_state, function(){
                        $('ul#search_city-menu').remove();
			$('select#search_city').removeAttr('disabled');
			$('select#search_city').selectmenu({
				style: 'dropdown',
				change: function () {
					$('#search_city-button').addClass('black');
				}
			});
			$('.remove').remove();
		});
	});
	
	//page numbers plugin
	$('div#wp_page_numbers ul li:last').addClass('next-page');
	$('div#wp_page_numbers ul li:eq(1)').addClass('prev-page');
	$('li.next-page a').text('');
	$('<img src="/wp-content/themes/fearless/images/bullet_green-arrow.gif" />').appendTo('li.next-page a');
	$('li.prev-page a').text('');
	$('<img src="/wp-content/themes/fearless/images/bullet_green-arrow-flipped.gif" />').appendTo('li.prev-page a');
	
	//no search results button
	$('form#noresults-searchform input#noresults-searchsubmit').attr('value','');

});
