// JavaScript Document
(function($) {
	jQuery.fn.float= function(settings){
	if(typeof settings == "object"){
		settings = jQuery.extend({
			//延迟
			delay : 1000,
			//位置偏移
			offset : {
				left : 0,
				right : 0,
				top : 0,
				bottom : 0
			},
			style : null, //样式
			width:100,  //宽度
			height:200, //高度
			position:"rm" //位置
		}, settings || {});	
		var winW = $(window).width();
		var winH = $(window).height();
		
		 //根据参数获取位置数值
		function getPosition($applyTo,position){
			var _pos = null;
			switch(position){
				case "rm" : 
					$applyTo.data("offset","right");
					$applyTo.data("offsetPostion",settings.offset.right);
					_pos = {right:settings.offset.right,top:winH/2-$applyTo.innerHeight()/2};
				break;
				case "lm" :
					$applyTo.data("offset","left");
					$applyTo.data("offsetPostion",settings.offset.left);
					_pos = {left:settings.offset.left,top:winH/2-$applyTo.innerHeight()/2};
				break;
				case "rb" :
					_pos = {right:settings.offset.right,top:winH - $applyTo.innerHeight()};
				break;
				case "lb" :
					_pos = {left:settings.offset.left,top:winH - $applyTo.innerHeight()};
				break;
				case "l" : 
					_pos = {left:settings.offset.left,top:settings.offset.top};
				break;
				case "r" : 
					_pos = {right:settings.offset.right,top:settings.offset.top};
				break;				
				case "t" :
					$applyTo.data("offset","top");
					$applyTo.data("offsetPostion",settings.offset.top);					
					_pos = {left:settings.offset.left,top:settings.offset.top};
				break;
				case "b" :
					$applyTo.data("offset","bottom");
					$applyTo.data("offsetPostion",settings.offset.bottom);					
					_pos = {left:settings.offset.left,top:winH - $applyTo.innerHeight()};				
				break;
			}
			return _pos;
		}
		//设置容器位置
		function setPosition($applyTo,position,isUseAnimate){
			var scrollTop = $(window).scrollTop();
			var scrollLeft = $(window).scrollLeft();
			var _pos = getPosition($applyTo,position);
			_pos.top += scrollTop;
			isUseAnimate && $applyTo.stop().animate(_pos,settings.delay) || $applyTo.css(_pos);
		} 
		return this.each(function(){
			var $this =  $(this);
			$this.css("position","absolute");
			settings.style && $this.css(settings.style);
			setPosition($this,settings.position);
			$(this).data("isAllowScroll",true);
			$(window).scroll(function(){
				$this.data("isAllowScroll") && setPosition($this,settings.position,true);
			});
		})	
	}else{
		var speed = arguments.length > 1 && arguments[1] || "fast"; 
		this.each(function(){		   
			if(settings == "clearOffset"){
					var _c = {};
					if($(this).data("offset")){
						 _c[$(this).data("offset")] = 0; 
						 $(this).data("isAllowScroll",false);
						 $(this).stop().animate(_c,speed);
					}
			}else if(settings == "addOffset"){
					var _c = {};
					if($(this).data("offset") && $(this).data("offsetPostion")){
						 _c[$(this).data("offset")] = $(this).data("offsetPostion"); 
						 $(this).stop().animate(_c,speed);
						 $(this).data("isAllowScroll",true);
					}
									   
			}else if(settings == "setScrollDisable"){
				$(this).data("isAllowScroll",false);
			}else if(settings == "setScrollUsable"){
				$(this).data("isAllowScroll",true);	
					}
				})
			}
		}	
})(jQuery);
	
(function($) {
	$.fn.marquee = function(o) {
		//获取滚动内容内各元素相关信息
		o = $.extend({
			speed:		parseInt($(this).attr('speed')) || 30, // 滚动速度
			step:		parseInt($(this).attr('step')) || 1, // 滚动步长
			direction:	$(this).attr('direction') || 'up', // 滚动方向
			pause:		parseInt($(this).attr('pause')) || 1000 // 停顿时长
		}, o || {});
		var dIndex = jQuery.inArray(o.direction, ['right', 'down']);
		if (dIndex > -1) {
			o.direction = ['left', 'up'][dIndex];
			o.step = -o.step;
		}
		var mid;
		var div 		= $(this); // 容器对象
		var divWidth 	= div.innerWidth(); // 容器宽
		var divHeight 	= div.innerHeight(); // 容器高
		var ul 			= $("ul", div);
		var li 			= $("li", ul);
		var liSize 		= li.size(); // 初始元素个数
		var liWidth 	= li.width(); // 元素宽
		var liHeight 	= li.height(); // 元素高
		var width 		= liWidth * liSize;
		var height 		= liHeight * liSize;
		if ((o.direction == 'left' && width > divWidth) || 
			(o.direction == 'up' && height > divHeight)) {
			// 元素超出可显示范围才滚动
			if (o.direction == 'left') {
				ul.width(2 * liSize * liWidth);
				if (o.step < 0) div.scrollLeft(width);
			} else {
				ul.height(2 * liSize * liHeight);
				if (o.step < 0) div.scrollTop(height);
			}
			ul.append(li.clone()); // 复制元素
			mid = setInterval(_marquee, o.speed);
			div.hover(
				function(){clearInterval(mid);},
				function(){mid = setInterval(_marquee, o.speed);}
			);
		}
		function _marquee() {
			// 滚动
			if (o.direction == 'left') {
				var l = div.scrollLeft();
				if (o.step < 0) {
					div.scrollLeft((l <= 0 ? width : l) + o.step);
				} else {
					div.scrollLeft((l >= width ? 0 : l) + o.step);
				}
				if (l % liWidth == 0) _pause();
			} else {
				var t = div.scrollTop();
				if (o.step < 0) {
					div.scrollTop((t <= 0 ? height : t) + o.step);
				} else {
					div.scrollTop((t >= height ? 0 : t) + o.step);
				}
				if (t % liHeight == 0) _pause();
			}
		}
		function _pause() {
			// 停顿
			if (o.pause > 0) {
				var tempStep = o.step;
				o.step = 0;
				setTimeout(function() {
					o.step = tempStep;
				}, o.pause);
			}
		}
	};
})(jQuery);

$(document).ready(function(){
	var jq=jQuery.noConflict();
	
	jq("#to-right").float({position:"rm"});
	 
	jq('.marquee').each(function() {
		jq(this).marquee();
	});
	
	jq('#logos').marquee({  
	direction: "left",  
	step: 1,  
	pause: 3000 ,
	speed: 1,
	auto: 1
	});
	
	jq('#plBox').marquee({  
	direction: "up",  
	step: 1,  
	pause: 3000 ,
	speed: 1,
	auto: 1
	});
	
	jq('#rmpj').hover(function(){
		jq('#pjBox .title a').removeClass();
		jq('#rmpj').addClass('rmpj');
		jq('#pjBox div').hide();
		jq('#rmpjBox').show();
		});
	jq('#case').hover(function(){
		jq('#pjBox .title a').removeClass();
		jq('#case').addClass('case');
		jq('#pjBox div').hide();
		jq('#caseBox').show();
		});
	jq('#lyej').hover(function(){
		jq('#pjBox .title a').removeClass();
		jq('#lyej').addClass('lyej');
		jq('#pjBox div').hide();
		jq('#lyejBox').show();
		});
			
	jq('#proBoxNew').hover(function(){
		jq('#title').removeClass();
		jq('#title').addClass('title');
		jq('#hotBox').hide();
		jq('#newBox').show();
		});
	jq('#proBoxHot').hover(function(){
		jq('#title').removeClass();
		jq('#title').addClass('titled');
		jq('#hotBox').show();
		jq('#newBox').hide();
		});	
		
	jq(".addFav").click(function(){
	var ctrl =(navigator.userAgent.toLowerCase()).indexOf('mac')!=-1?'Command/Cmd':'CTRL';
	if(document.all){
		window.external.addFavorite('http://www.comsun.com.cn','广州市金佳信通信产品发展有限公司')
		}else if(window.sidebar){
	window.sidebar.addPanel('广州市金佳信通信产品发展有限公司','http://www.comsun.com.cn',"")
	}else{
	alert('您可以尝试通过快捷键'+ ctrl +' + D 加入到收藏夹~')
	}
	});
		
	});
