$(function(){
	
	//fix all outline in the IE6
	if($.browser.msie){
		$('a').focus(function(){this.blur();}); 
		$('area').focus(function(){this.blur();}); 
	}
	
	//share
	(function(){
		$.share({
			id:'.share_area',
			url:'http://www.sina.com.cn',
			title:'PHONO SOLAR'
		});
	})();
	
	
	//choose_language
	(function(){
		var $choose_language = $('div#choose_language');
		$choose_language.hover(function(){
			$(this).addClass('choose_language_hover');
			$('div.lawe').slideDown();
		},function(){
			$(this).removeClass('choose_language_hover');
			$('div.lawe').slideUp();
		});
	})();
	
	
	//nav
	(function(){
	
		var $fath = $('#nav li.fath');
		var $old_width;
		
		$fath.each(function(i){
			$nowObj = $(this);
			$nowObj.attr("rel",function(){
								return 	 parseInt($nowObj.find(".child_nav").css('width'))-1;	
							});					
		});
		
		$fath.hover(function(){
			if(!$(this).find('div.child_nav').is(':animated')){
				$(this).addClass('current').siblings().removeClass('current');
				//$(this).find('div.child_nav').stop(true,true).slideDown(200);
				 var $fa_with = $(this).attr('rel');
				 $(this).find('div.child_nav').css({width:0}).show().stop(true,true).animate({width:$fa_with},300,'easeOutQuint');
			}
		},function(){
				$fath.removeClass('current');
			//	$fath.find('div.child_nav').stop(true,true).slideUp(200);
				$fath.eq($(this).index()).find('div.child_nav').stop(true,true).animate({width:0},100,'easeOutQuint',function(){
					$(this).css({width:$old_width}).hide();
				});
		});
	
	})();
	
	//video_click
	(function(){
		$('#video_click').click(video_fn);
		$('#click_p').click(video_fn);
		$('#product_p').click(product_fn);
		
		function video_fn(){
			$('div#video_content_area').load('video.php');
			$.lightBox('.video_content');
			$("div[class^=eaMask]").attr('id','video_button_close');
		}
		
		function product_fn(){
			$('div#video_content_area_product').load('product_video.php');
			$.lightBox('.video_content');
			$("div[class^=eaMask]").attr('id','video_button_close');
		}
		
		$('div.video_content .popClose').click(function(){
			$('div#video_content_area').html('');
			$('div#video_content_area_product').html('');
		});
		
		$('#video_button_close').live('click',function(){
			$('div#video_content_area').html('');
			$('div#video_content_area_product').html('');
		});
		
		$.garlleyImg({
				obj:'.theindexvideo .v_list',
				ic:'.video_control,.theindexvideo',
				intv:3*1000,
				iact:1000,
				control:".video_control"
		});
		
	})();
	
	//input_value
	(function(){
		
		var $search_text = $('input.search_text');
		var $email_text  = $('input.email_text');
		var $email_but   = $('a.email_but');
		var $search_but   = $('a.search_but');
		
		$($search_text).each(function(i) {
			defaultCheck(this,$search_but);
        });
		
		$email_text.each(function(i) {
            defaultCheck(this,$email_but);
        });
		
		$search_but.click(function(){
			
		});
		
		function defaultCheck(the,subit){
			$(the).focus(function(){
				if($(the).val() == defaultValue_fn(the)){
					$(the).val('');
				}	
			}).blur(function(){
				if($(the).val() == ''){
					$(the).val(defaultValue_fn(the));
				}
			}).keydown(function(the){
				if(the.keyCode == 13){
					subit.click();
				}
			});
		}
		
		function defaultValue_fn(co1){
			return $(co1)[0].defaultValue;
		}
		
		
		$search_but.click(function(){
			if($('input.search_text').val()!= defaultValue_fn('input.search_text') && $('input.search_text').val() !=null){
				location.href ='search.php?keyword='+$('input.search_text').val();	 
			}else{
				alert('Enter the keywords!');
			}
			
		});
		
		
	})();

	//index_banner
	(function(){
		
		var $show          = $('ul.showImg_list');
		var $current       = $('div.chooseImg_list ul');
		var $show_item     = $show.find('li');
		var $current_item  = $current.find('li');
		var $current_width = $current_item.width();
		var $current_index = -1;
		var $auto_start    = null;
		var $big,$small;
		
	
		
		$current_item.click(function(){
			if(!$show_item.find('img').is(':animated') && !$(this).find('img').is(':animated')){
				$big   = $(this).attr('big');
				$small = $(this).attr('small');
				$current_index = $(this).index();
				banner_animte($(this),$big,$small);
			}	
		});
		
		
		function banner_animte(the,b,s){
			
			the.attr('big',$show_item.attr('big'));
			the.attr('small',$show_item.attr('small'));
			
			
			$show_item.attr('big',b);
			$show_item.attr('small',s);
			$show_item.find('img').hide();
			$show_item.find('img').attr('src',b).fadeIn(1000);
			the.find('img').hide();
			the.find('img').attr('src',the.attr('small')).fadeIn(300);
			
		}
		
		
		$current.hover(function(){
			
			if($auto_start){
				clearInterval($auto_start);
				$auto_start = null;
			}	
			
		},function(){
			$auto_start = setInterval(function(){
				$current_index++;
				if($current_index == 2){
					$current_index = 0;
				}
				banner_animte($current_item.eq($current_index),
					$current_item.eq($current_index).attr('big'),
					$current_item.eq($current_index).attr('small')
				);
				
				
			},4000);
			
		}).trigger('mouseleave');
		
		
		
	})();



/*		(function(){
		
		var $show          = $('ul.showImg_list');
		var $current       = $('div.chooseImg_list ul');
		var $show_item     = $show.find('li');
		var $current_item  = $current.find('li');
		var $current_width = $current_item.width();
		var $current_index = 0;
		var $auto_start    = null;
		var $rel = 0;
		
		$show_item.each(function(i) {
            $(this).attr('rel',i);
        });
		
		$current_item.each(function(i) {
            $(this).attr('rel',i);
        });
		
		$current_item.click(function(){
			$current_index = $(this).index()+1;
			$rel = $(this).attr('rel');
			if($current_index ==1){
				showAnimate_left($rel);
			}
			else{
				showAnimate_right($rel);
			}
		});
		
		
		function showAnimate_left(num){
			
			if( !$current.is(':animated')){	
			
				$show.find("li[rel='"+num+"']").fadeIn(1000).siblings().fadeOut(1000);
				$current.animate({marginLeft:'-'+$current_width},1000,function(){
					$current.css({marginLeft:0}).find("li[rel='"+num+"']").appendTo($current);
				});	
				
			}
		}
		
		function showAnimate_right(num){
			
			if( !$current.is(':animated')){
				$show.find("li[rel='"+num+"']").fadeIn(1000).siblings().fadeOut(1000);
				$current.css({marginLeft:-$current_width}).find("li:last").prependTo($current);;
				$current.animate({marginLeft:0},1000);
		
			}
		}
		
		$current.hover(function(){
			
			if($auto_start){
				clearInterval($auto_start);
				$auto_start = null;
			}	
			
		},function(){
			$auto_start = setInterval(function(){
				$rel = $('div.chooseImg_list ul li').eq(2).attr('rel');
				$rel++;	
				if($rel == 3){
					$rel = 0;
				}	
				showAnimate_left($rel);

			},8000);
			
		}).trigger('mouseleave');
		
		
		
	})();*/






	//index_center
	(function(){
		
		var $center_left  = $('a#index_center_left');
		var $center_right = $('a#index_center_right');
		var $index_p      = $("div[class^='index_p']");
		var $index_nav    = $('div.index_nav');
		var $center_index = 0;
		var $auto_center = null;
		
		$center_right.click(function(){
			
			$center_index ++;
			if($center_index == $index_p.length){
				$center_index = 0;
			}
			showIndex_fn($center_index);
		});
	
		$center_left.click(function(){
			$center_index --;
			if($center_index == -1){
				$center_index = $index_p.length-1;
			}
			showIndex_fn($center_index);
		});
		
		
		function showIndex_fn(un){
			$index_p.eq(un).fadeIn(600).siblings("div[class^='index_p']").fadeOut(600);
		}
		
		$index_nav.hover(function(){
			
			if($auto_center){
				clearInterval($auto_center);
				$auto_center = null;
			}
			
		},function(){
			
			$auto_center = setInterval(function(){
				$center_index ++;
				if($center_index == $index_p.length){
					$center_index = 0;
				}
				showIndex_fn($center_index);
				
			},3000);
			
		});
		
		$auto_center = setInterval(function(){
				$center_index ++;
				if($center_index == $index_p.length){
					$center_index = 0;
				}
				showIndex_fn($center_index);
				
			},3000);
		
	})();



	//index_left
	(function(){
		
		var $index_topImg      = $('div.index_top img.list_item');
		var $index_topP        = $('div.index_top p span');
		var $oth_li            = $('div.index_leftMain div.index_bottom li');
		var $src_img,$html_p;
		var $index_left_right  = $('a#index_left_right');
		var $index_left_left   = $('a#index_left_left');
		var $left_index        = -1;
		var $index_left        = $('div.index_left');
		var $auto_left         = null;
		
		
		$oth_li.click(function(){
			
			show_Wq($(this).index());
			
			
		});
		
		$index_left_right.click(function(){
			$left_index++;
			if($left_index == $oth_li.length){
				$left_index = 0;
			}
			show_Wq($left_index);
			
		});
		
		$index_left_left.click(function(){
			$left_index--;
			if($left_index == -1){
				$left_index = $oth_li.length -1 ;
			}
			show_Wq($left_index);
			
		});
		
		
		
		function show_Wq(yt){
			
			$index_topImg.fadeOut(100);
			$index_topP.hide();
			
			$src_img = $index_topImg.attr('src');
			$html_p  = $index_topP.html();
			
			$index_topImg.stop(true,true).fadeIn(600).attr('src',$oth_li.eq(yt).find('img').attr('src'));
			$index_topP.stop(true,true).fadeIn(600).html($oth_li.eq(yt).find('span').html());
			
			$oth_li.eq(yt).find('img').attr('src',$src_img);
			$oth_li.eq(yt).find('span').html($html_p);
			
		}
		
		
		$index_left.hover(function(){
			
			/*if($auto_left){
				clearInterval($auto_left);
				$auto_left = null;
			}*/
			
			
		},function(){
			
			/*$auto_left = setInterval(function(){
				$left_index ++;
				if($left_index == $oth_li.length){
					$left_index = 0;
				}
				show_Wq($left_index);
				
			},3000);*/
			
			
		});
		
		
		/*$auto_left = setInterval(function(){
				$left_index ++;
				if($left_index == $oth_li.length){
					$left_index = 0;
				}
				show_Wq($left_index);
				
			},3000);*/
		
	})();





	(function(){
		$(".drop_down_list").click(function(){
		var $nowobj = $(this);
		var st = ""; 
		var $ul = $(this).next("ul.drop_down_ul");
		$(this).next("ul.drop_down_ul").fadeIn(300);	 
		$ul.hover(function(){ $(this).css("display","block"); clearTimeout(st); }, function(){ $ul.slideUp(100); });
		$ul.find("li").click(function(){
								var _sNowtext = $(this).text();
								var _sNowval = $(this).attr("rel");
								$nowobj.html(_sNowtext);
								$("#"+$ul.attr("comment")).val(_sNowval);
								$ul.slideUp(100);							
							});
		$nowobj.mouseout(function(){st = setTimeout(function(){$ul.slideUp(100);},3000); });
		});
	})();

	(function(){
		$("input.tip").focus(function(){ if($(this).val()==$(this)[0].defaultValue){ $(this).val(""); } }).blur(function(){if($(this).val()==""){ $(this).val($(this)[0].defaultValue); }});	 
	})();
	
	$(".left_comm dl.menu.current>dd:first").css({"padding-top":"5px","background-position":"13px 13px"});
	$(".left_comm dl.menu.current>dd:last").css({"padding-bottom":"5px","background-position":"13px 8px"});
});
