$(document).ready(function() {

    var is_ie6 = false;
    if( (typeof document.body.style.maxHeight) === "undefined") {
        is_ie6 = true;
    }

    // This Jquery code block for new Top Navigation
    $("#top-menu li.top-level").hover(function(){
        $("#top-menu li.top-level ul.drop-menu").css("display", "none");
		$(this).find("ul.drop-menu").fadeIn(300);
    }, function(){
		$(this).find("ul.drop-menu").fadeOut(400);
    });


    // This following Jquery code block is for new Site Search Box
	if ( $("#search-theme-form #filter").length ) {
		$("#search-theme-form #filter").hide();
		createSiteSearchOptionsDropDown();
		siteSearchEventsHandler();
	}

	$(document).bind('click', function(e) {
		var $clicked = $(e.target);
		if (! $clicked.parents().hasClass("select-dropdown")) {
			$(".select-dropdown dd ul").hide();
			$(".drop-down-clean-arrow").css('backgroundPosition', '0 0');
		}
	});

    // This following Jquery code block is for Homepage tabbed content section
    $(".tab-content").hide(); //Hide all content
    $("ul.tabbed li:first").addClass("active").show(); //Activate first tab
    $(".tab-content:first").show(); //Show first tab content

        //On Click Event
    $("ul.tabbed li").click(function() {
        $("ul.tabbed li").removeClass("active"); //Remove any "active" class
        $(this).addClass("active"); //Add "active" class to selected tab
        $(".tab-content").hide(); //Hide all tab content

        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //Fade in the active ID content
        return false;
	});
    // End-->

    if( $.isFunction($.fn.cycle) ) { // checking first if jquery cycle plugin library is included or not
      // This following Jquery code block is for Homepage Top slideshow
      $("#slider-top")
         .after('<div class="slider-top-pagination">')
                .cycle({
                          fx:      'fade', 
                          speed:   2000, 
                          timeout: 7000, 
                          pause:   1,
                          next:    '#next2', 
                          prev:    '#prev2', 
                          pager:   '.slider-top-pagination' 
                       });
      // End-->

      // This following Jquery code block is for bottom slideshows
      $("#slider-bottom")
         .after('<div class="slider-bottom-pagination">')
                .cycle({
                          fx:      'scrollLeft', 
                          speed:   1000, 
                          timeout: 7000, 
                          pause:   1,
                          next:    '#next2', 
                          prev:    '#prev2', 
                          pager:   '.slider-bottom-pagination' 
                       });
      // End-->
    } // endif

    // This jquery below is to select the default texts in "Free Hypnosis Course" Signup fields
    //$(".course-signup-form").find("input[type=text]").click(function() { selectAllText($(this)) });


	if(is_ie6) {
	   //$("#sidebar-left .vertical-shadow-seprator").css("height", $("#sidebar-left").height());
       $("#sidebar-left .vertical-shadow-seprator").css("height", $("#sidebar-left").height() -26);
	   $("#sidebar-left .vertical-shadow-seprator").find(".shadow-bottom-part").css( "top", $(this).find(".shadow-bottom-part").parent().height()-36 );
	   
	   $("#sidebar-left .block").find(".shadow-box-left-bg").css("height", $(this).find(".shadow-box-left-bg").parent().height());
	   $("#sidebar-left .block").find(".shadow-box-right-bg").css("height", $(this).find(".shadow-box-right-bg").parent().height());
	   $("#sidebar-left .block").find(".shadow-box-bot-bg").css( "top", $(this).find(".shadow-box-bot-bg").parent().height()+10 );

	   $("#sidebar-left-blue .vertical-shadow-seprator").css("height", $("#sidebar-left-blue").height());
	   $("#sidebar-left-blue .block").find(".shadow-box-left-bg").css("height", $(this).find(".shadow-box-left-bg").parent().height());
	   $("#sidebar-left-blue .block").find(".shadow-box-right-bg").css("height", $(this).find(".shadow-box-right-bg").parent().height());
	   $("#sidebar-left-blue .block").find(".shadow-box-bot-bg").css( "top", $(this).find(".shadow-box-bot-bg").parent().height()+10 );

	   $("#sidebar-left-green .vertical-shadow-seprator").css("height", $("#sidebar-left-green").height());
	   $("#sidebar-left-green .block").find(".shadow-box-left-bg").css("height", $(this).find(".shadow-box-left-bg").parent().height());
	   $("#sidebar-left-green .block").find(".shadow-box-right-bg").css("height", $(this).find(".shadow-box-right-bg").parent().height());
	   $("#sidebar-left-green .block").find(".shadow-box-bot-bg").css( "top", $(this).find(".shadow-box-bot-bg").parent().height()+10 );
    }
	
});

function createSiteSearchOptionsDropDown(){
	var search_filter_option = $("#search-theme-form #filter");
	var selected = search_filter_option.find("option[selected]");
	var options = $("option", search_filter_option);

	$("#site-search-options").append('<dl id="select-options" class="select-dropdown"></dl>');
	$("#site-search-options #select-options").append('<dt><a class="position-rel" href="javascript:void()">' + selected.text() + 
								'<span class="value">' + selected.val() + 
								'</span><span class="drop-down-clean-arrow position-abs"></span></a></dt>');
	$("#site-search-options #select-options").append('<dd class="position-rel"><ul class="position-abs"></ul></dd>');

	options.each(function(){
		$("#site-search-options #select-options dd ul").append('<li><a href="javascript:void()">' + 
										  $(this).text() + '<span class="value">' + 
										  $(this).val() + '</span><span class="drop-down-clean-arrow position-abs"></span></a></li>');
	});
}

function siteSearchEventsHandler() {
	$("#site-search-options .select-dropdown dt a").click(function() {
		if ($("#site-search-options .select-dropdown dd ul").is(":visible")) {
			$("#site-search-options .drop-down-clean-arrow").css('backgroundPosition', '0 0');
		}
		else {
			$("#site-search-options .drop-down-clean-arrow").css('backgroundPosition', '-7px 0');
		}

		$("#site-search-options .select-dropdown dd ul").toggle();
	});


	$("#site-search-options .select-dropdown dd ul li a").click(function() {
		var text = $(this).html();
		$("#site-search-options .select-dropdown dt a").html(text);
		$("#site-search-options .select-dropdown dd ul").hide();
		$("#site-search-options .drop-down-clean-arrow").css('backgroundPosition', '0 0');

		var search_filter_option = $("#search-theme-form #filter");
		search_filter_option.val($(this).find("span.value").html())
	});

	$("#search-theme-form #myGgSearchTop").click(function() {
		if($(this).val() == "Search") {
			$(this).val("");
		}
		else {  
			$(this).select();
		}
	});		

}

function selectAllText(textbox) {
    textbox.focus();
    textbox.select();
}

function showHideNextElement(element, next_element, is_ie6) {
    
    if( $(element).next(next_element).css("display") ) {
        $(element).next(next_element).css("display", "none");
    }
	$(element).click(function(){
        $(element).next(next_element).toggle();
		if(is_ie6) {
		   var shadow_bot_bg = $("#sidebar-left .block").find(".shadow-box-bot-bg");
		   var shadow_left_bg = $("#sidebar-left .block").find(".shadow-box-left-bg");
		   var shadow_right_bg = $("#sidebar-left .block").find(".shadow-box-right-bg");
           $(shadow_left_bg).css( "height", $(shadow_left_bg).parent().height()+10 );
           $(shadow_right_bg).css( "height", $(shadow_right_bg).parent().height()+10 );
           $(shadow_bot_bg).css( "top", $(shadow_bot_bg).parent().height()+4 );
           if( $(element).next(next_element).css("display") == "block" ) { 
               $(shadow_left_bg).find(".shadow-box-left-bg-bot").css( "bottom", 16 );
               $(shadow_right_bg).find(".shadow-box-right-bg-bot").css( "bottom", 16 );
			   $("#sidebar-left .vertical-shadow-seprator").css("height", $("#sidebar-left").height());
           }
           else { 
               $(shadow_left_bg).find(".shadow-box-left-bg-bot").css( "bottom", 15 );
               $(shadow_right_bg).find(".shadow-box-right-bg-bot").css( "bottom", 15 );
			   $("#sidebar-left .vertical-shadow-seprator").css("height", $("#sidebar-left").height());
           }
		}
    });
}
