//jQuery.extend({
//setHomepage: function(url) {
//if (document.all) {
// document.body.style.behavior = 'url(#default#homepage)';
// document.body.setHomePage(url);
//}
//else if (window.sidebar) {
// if (window.netscape) {
//  try {
//   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
//  }
//  catch (e) {
//   var strTemp = '';
//   strTemp += "this action was aviod by your browser,";
//   strTemp += "if you want to enable,please enter about:config in your address line,";
//   strTemp += "and change the value of signed.applets.codebase_principal_support to true";
//   alert(strTemp);
//  }
// }
//  try{
//	var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
//	prefs.setCharPref('browser.startup.homepage', url);
//  }	
//  catch(e){
//	alert(e);	
//  }
//}
//}
//});


$(document).ready(function(){ 
						   
// News Ticker 
	$("div.top-news ul.news-item").newsTicker();

// Search Dropdown
	$(".dropdown dt").click(function() {
	    $(".dropdown dd ul").toggle();
	});		

	$(".dropdown dd ul li a").click(function() {
	    var text = $(this).html();
	    var site = $(this).attr("name");
	    $("#site_name").val(site);	
	    $(".dropdown dt a span").html(text);
	    $(".dropdown dd ul").hide();
	});		

	$(document).bind('click', function(e) {
	    var $clicked = $(e.target);
	    if (! $clicked.parents().hasClass("dropdown"))
	        $(".dropdown dd ul").hide();
	});

// News Ticker Dropdown
	$(".dropnews dt").click(function() {
	    $(".dropnews dd ul").toggle();
	});	
	$(".dropnews dd ul li a").click(function() {
	    $(".dropnews dd ul").hide();
	});			
	
	$(document).bind('click', function(e) {
	    var $clicked = $(e.target);
	    if (! $clicked.parents().hasClass("dropnews"))
	        $(".dropnews dd ul").hide();
	});

// Searc Text Teplace
    $('input.search-key').focus(function () {
	    var $this = $(this);
	    if ($this.val()==$this.attr('title')) { $this.val(''); $this.css('color','#000'); }
    });
    $('input.search-key').blur(function () {
	    var $this = $(this);
	    if ($this.val()=='') { $this.val($this.attr('title')); $this.css('color','#aaa'); };
    });						   
	
// Theme
    main_page_url = "http://www.buddhistdoor.com/";
	function tm_clear() {
		$("body").removeClass("tm1");
		$("body").removeClass("tm2");
		$("body").removeClass("tm3");
		$("body").removeClass("tm4");
		$("div#header div.top-bd-control ul.theme a").removeClass("active");
	}
    theme=2;
	if ($.cookie("theme")!=false) {
        		tm_clear();
		if ($(this).attr("title")==0) {
                        tm_clear();
                        $(this).addClass("active");
                }
		else
		{
			tm_clear();
                        $(this).addClass("active");
                        theme = $.cookie("theme");
                        if($.cookie("theme")==null)
                        {
                            theme=2;
                        }
                        $("body").addClass("tm"+theme);
		}
   	}
     var site = $("#site").val();
        var site_language = $("#site_language").val();
        logo = main_page_url + "assets/images/"+"tm"+theme+'/'+site_language+'/'+site+'.png';
        $("#header-logo").attr("src",logo);

	
	$("div#header div.top-bd-control ul.theme a").click(function () {
		$.cookie("theme",$(this).attr("title"),{ path: '/', domain: 'buddhistdoor.com', expires: 3650 });
		if ($(this).attr("title")==0) {
			tm_clear();
			$(this).addClass("active");
		}
		if ($(this).attr("title")==1) {
			tm_clear();
			$(this).addClass("active");
			$("body").addClass("tm1");
		}	
		if ($(this).attr("title")==2) {
			tm_clear();
			$(this).addClass("active");
			$("body").addClass("tm2");
		}	
		if ($(this).attr("title")==3) {
			tm_clear();
			$(this).addClass("active");
			$("body").addClass("tm3");
		}	
		if ($(this).attr("title")==4) {
			tm_clear();
			$(this).addClass("active");
			$("body").addClass("tm4");
		}
        var site = $("#site").val();
        var site_language = $("#site_language").val();
        logo = main_page_url + "assets/images/"+"tm"+$(this).attr("title")+'/'+site_language+'/'+site+'.png';
        $("#header-logo").attr("src",logo);	
    });
		
/* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Header Template JS Above @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */
	
// Home Page JS
	$("ul.tab-list").tabs("#tab-all > div").history(); 
	$('#banner').cycle({fx: 'fade',timeout:6000,delay:-2000 });
//	$('#set_homepage').click(function() {
//		$.setHomepage(location.href);
//	});
}); 

