/*图片轮换效果*/
function setGds(_id){
	var _gds = $('#'+_id);
	var _obj = _gds.find('.pop_pic li');
	var _item = _gds.find('.picBtn a');
	
	var _time = 2000;
	var _speed = 500;
	var _t;
	var _num = 0;
	var _tf = true;
	var _tf2 = true;
	
	$.each(_obj,function(i,e){
		$(e).css('z-index',99-i);
	});
	_obj.show();
	
	_gds.hover(function(){
		_tf = false;
	},function(){
		_tf = true;
	});
	_item.click(function(){
		if(!_tf2){return false;}
		_tf2 = false;
		clearTimeout(_t);
		var _int = parseInt($(this).html());
		var _ints = _int - 1;
		var _into = _ints - 1 - _num;
		if(_ints == _num){_tf2 = true;return false;}else{
			if(_ints > _num){
				if(_into>0){
					for(var i=0; i<_into; i++){
						$(_obj[_num + i + 1]).hide();
					}
				};
				$(_obj[_num]).fadeOut(_speed,function(){_tf2 = true;});
				_num = _ints;
				_item.removeClass('linkOn');
				$(_item[_num]).addClass('linkOn');
			}else{
				_num = _ints;
				$(_obj[_num]).fadeIn(_speed,function(){_tf2 = true;if(_into != -2){
					_into = Math.abs(_into) - 2;
					for(var i=0; i<_into; i++){
						$(_obj[_ints + i + 1]).show();
					}
				};});
				_num = _ints;
				_item.removeClass('linkOn');
				$(_item[_num]).addClass('linkOn');
			}
		}
		_t = setTimeout(function(){gdsNext()},_time);
	});
	
	function gdsGo(){
		_t = setTimeout(function(){gdsNext()},_time);
	};
	
	function gdsNext(){
		if(!_tf){gdsGo();return false;}
		if(_num < _obj.length - 1){
			$(_obj[_num]).fadeOut(_speed);
			_item.removeClass('linkOn');
			$(_item[_num + 1]).addClass('linkOn');
			_num+=1;
		}else{
			_num = 0;
			$(_obj[_num]).fadeIn(_speed,function(){_obj.show();});
			_item.removeClass('linkOn');
			$(_item[_num]).addClass('linkOn');
		}
		gdsGo();
	};
	gdsGo();
}
/*图片轮换效果 - end */

/*左导航效果*/
function setLeftNav() {
    var _obj = $('#leftNav');
    var _btn = _obj.find('h3');
    $.each(_btn, function (i, e) {
        var item = $(e).next('ul');
        $(e).click(function () {
            if (item.css('display') == 'block') {
                $(e).next('ul').hide();
                $(e).removeClass('linkOn');
                setLeftNavCookie();
            }
            else {
                $(e).next('ul').show();
                $(e).addClass('linkOn');
                setLeftNavCookie();
            }
        });
    });
    if ($.cookie('leftnav') != null) {
        var navstr = $.cookie('leftnav');
        var navarr = navstr.split(',');
        $.each($('#leftNav h3'), function (i, e) {
            if (navarr[i] == 1) {
                $(e).addClass('linkOn');
                $(e).next('ul').show();
            } else {
                $(e).removeClass('linkOn');
            }
        })
    } else {
        $($('#leftNav h3')[0]).addClass('linkOn');
        $($('#leftNav h3')[0]).next('ul').show();
    };
}
function setLeftNavCookie() {
    if ($.cookie('leftnav') == null) {
        $.cookie('leftnav', '0');
    };
    var navstr = $.cookie('leftnav');
    var navarr = navstr.split(',');
    var tmpstr = '';
    $.each($('#leftNav h3'), function (i, e) {
        if ($(e).next('ul').css('display') == 'block') {
            if (i == 0) {
                tmpstr += '1';
            } else {
                tmpstr += ',1';
            }
        } else {
            if (i == 0) {
                tmpstr += '0';
            } else {
                tmpstr += ',0';
            }
        };
    });

    $.cookie('leftnav', tmpstr);
}
/*左导航效果 - end*/

/*报价弹出框*/
function setPrice(){
	var _obj = $('#seachInp');
	var _box = $('#priceBox');
	var _item = _box.find('.cont a');
	_obj.focus(function(){
		_box.show();
		$.each(_item,function(i,e){
			$(this).click(function(){
				_item.removeClass('linkOn');
				$(this).addClass('linkOn');
				_obj.val($(this).html());
				_box.hide();
			});
			
		});
	}).blur(function(){
		//_box.hide();
	});
	$('#closeBtn').click(function(){
		_box.hide();
	});
	
}

/*报价弹出框 - end*/


function setMenu(_num) {
    $($('#head_nav li')[_num]).addClass('linkOn');
}

//jQuery插件Cookie
/*
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
* $.cookie('the_cookie'); //读取Cookie值
* $.cookie(’the_cookie’, ‘the_value’); //设置cookie的值
* $.cookie(’the_cookie’, ‘the_value’, {expires: 7, path: ‘/’, domain: ‘jquery.com’, secure: true});//新建一个cookie 包括有效期 路径 域名等
* $.cookie(’the_cookie’, ‘the_value’); //新建cookie
* $.cookie(’the_cookie’, null); //删除一个cookie
*/
jQuery.cookie = function (name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
