/*Recently:jiafei Updated Date: 2008-1-19 14:52*/
var duk = {};
duk.__init__ = function() {
	duk.initSearch();
}

duk.search = function(text, type) {
	text = encodeURIComponent(text);
	var searchUrl;
	if (type == 'search_title') {
		searchUrl = "search/" + text;
	} else if (type == 'search_body') {
		searchUrl = "search/" + text + "/a0-b2.html";
	} else if (type == 'search_all') {
		searchUrl = "search/" + text + "/a0-b0.html";
	} else if (type == 'search_user') {
		// TODO
		searchUrl = "search/";
	} else if (type == 'search_problem') {
		searchUrl = "search/" + text + "/a3-b0.html";
	}
	window.open(searchUrl);
}

duk.initSearch = function() {
	duk._initSearchBox();
	jQuery("#opt, #searchoption").bind('mouseenter', function(event) {
		if (jQuery("#searchoption").is(':hidden')) {
			var offset = jQuery("#opt").offset();
			var left = offset.left - 5 + 'px';
			var top = offset.top - 21 + 'px';
			jQuery("#searchoption").css('top', -17).css('left', 180).show();
		}
	});

	jQuery("#searchoption").bind('mouseleave', function() {
		jQuery("#searchoption").hide();
	});
}

duk._initSearchBox = function() {
	jQuery("#search_keywords").toggleVal( {
		focusClass :"input_sb2",
		populateFrom :"alt"
	}).keypress( function(e) {
		if (e.which == 13) {
			duk.search(jQuery("#search_keywords").val(), "search_all");
			jQuery("#search_keywords").blur();
		}
	});
	
	jQuery("#searchoption").click( function(e) {
		var text = jQuery("#search_keywords").val();
		var type = e.target.className;
		duk.search(text, type);
	});
}

duk.initSecondaryNavigation = function() {
	duk._initSearchBox();
	jQuery("#brandopt span").css({cursor:"pointer",fontSize:"12px"});
	jQuery("#brandopt span, #brandopt a:first").click( function(e) {
		var text = jQuery("#search_keywords").val();
		if (text == "请输入搜索关键词...") {
			alert("输入搜索关键词...");
			return ;
		}
		duk.search(text, "search_all");
	});
	
	jQuery("#brandopt, #searchoption").bind('mouseenter', function(){
		jQuery("#brandopt").children(":first").addClass("mouseover");
		jQuery("#searchoption").show();
	});
	
	jQuery("#brandopt, #searchoption").bind('mouseleave', function(){
		jQuery(this).prev().removeClass("mouseover");
		jQuery("#searchoption").hide();
	});

	jQuery("#pbobj > a, #pbtar").bind('mouseenter', function(){
		jQuery("#pbtar").show();
		jQuery("#pbobj a").addClass('mouseover');
	});
	
	jQuery("#pbobj, #pbtar").bind('mouseleave', function(){
		jQuery("#pbtar").hide();
		jQuery("#pbobj a").removeClass('mouseover');
	});
	
	jQuery("#ppobj a, #pptar").bind('mouseenter', function(){
		jQuery("#ppobj a").addClass('mouseover');
		jQuery("#pptar").show();
	});
	
	jQuery("#ppobj, #pptar").bind('mouseleave', function(){
		jQuery("#ppobj a").removeClass('mouseover');
		jQuery("#pptar").hide();
	});

	if (!jQuery.cookie('visited')) {
		var date = new Date();
		date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));
		jQuery.cookie('visited', '1', { path: '/', domain: '19lou.com', expires: date });
		jQuery("#tips_cfloor").show();
		jQuery("#tips_cfloor a").click(function(){
			jQuery("#tips_cfloor").hide();
			return false;
		});
	}
	
	jQuery('#notice').cycle({
	  	pause:1,
	  	timeout: 4000,
	  	speed: 400,
	  	height: 8,
	  	fx: 'scrollUp'
	});
	
	if(jQuery(".dktemp").width() < 1006) jQuery(".dktemp").css("width","1006px");
}

duk.util = {};
duk.util.setHomepage = function(obj, url) {
	if (_dk.client.isIE) {
		obj.style.behavior = "url(#default#homepage)";
		obj.setHomePage(url);
	} else {
		return false;
	}
}

duk.util.setCopy = function(_sTxt) {
	if (navigator.userAgent.toLowerCase().indexOf('ie') > -1) {
		clipboardData.setData('Text', _sTxt);
		alert("网址“" + _sTxt + "”\n已经复制到您的剪贴板中\n您可以使用Ctrl+V快捷键粘贴到需要的地方");
	} else {
		prompt("请复制网站地址:", _sTxt);
	}
}

duk.util.addBookmark = function(site, url) {
	if (navigator.userAgent.toLowerCase().indexOf('ie') > -1) {
		window.external.addFavorite(url, site)
	} else if (navigator.userAgent.toLowerCase().indexOf('opera') > -1) {
		return;
	} else {
		return;
	}
}

jQuery(window).resize(function(){	
	if(document.documentElement.clientWidth <= 1006){
		jQuery(".dktemp").css({width:"1006px"});
	}else{
		jQuery(".dktemp").css({width:"98%"});
	}
})