// oppo x903 JS

Cufon.replace(".en_font", {fontFamily : "Eurostile LT Std"}); 

//
var t = n = 0, count;
var counthtml="";
$(document).ready(function(){
	
	count=$(".design_interface img").length;
	for(var s=1; s<=count; s++){
		counthtml+='<a href=# title="'+s+'"></a>';
	}
	$(".switch_interface").append(counthtml);
	$(".switch_interface a:first-child").addClass("current");
	$(".design_interface img:not(:first-child)").hide();
	$(".switch_interface a").click(function() {
		var i = $(this).attr("title") - 1;
		n = i;
		if (i >= count) return;
		$(".design_interface img").filter(":visible").fadeOut(200).parent().children().eq(i).fadeIn(800);
		$(this).toggleClass("current");
		$(this).siblings().removeAttr("class");
		return false;
	});
	t = setInterval("showAuto()", 3000);
	$(".design_interface").hover(function(){clearInterval(t)}, function(){t = setInterval("showAuto()", 3000);});
})

function showAuto()
{
	n = n >=(count - 1) ? 0 : ++n;
	$(".switch_interface a").eq(n).trigger('click');
}



//
function installX(c_class, s_class) {
	$(s_class).each(function(i, s) {
		$(s).bind('click', function() {
			$(c_class).each(function(j, c){
				if (i == j) $(c).fadeIn();
				else $(c).fadeOut();
			});
			$(s_class).each(function(j, c){
				if (i == j) $(c).addClass('current');
				else $(c).removeClass('current');
			});
			return false;
		});			
	});
}

installX('.xc1', '.xs1');
installX('.xc2', '.xs2');
installX('.xc3', '.xs3');
installX('.xc4', '.xs4');


function scrollTo(next) {
	var top = $(window).scrollTop();
	var vtop=-50;
	var find = false;
	$('.feature_box').each(function(i, c) {
		c = $(c);
		if (next) {
			if (find || i == 0) return;
			if (c.offset().top > top) {
				find = c;
			}
		} else {
			if (c.offset().top < top) { // + c.height() > top && c.offset().top < top) {
				find = c;
			}
		}
	});
	if (find) {
		$('body,html').animate({scrollTop:find.offset().top + 'px'});
	}
}

//views_demo

//

/*bar*/
$(document).ready(function(){
   var $nav_bar= $("#nav_bar"),
        $win= $(window),
		$scrolls = $win.scrollTop(),
		$top=140;
		$ittop=$win.height()+$win.scrollTop()-$top;
		
    $win.scroll(function() {
        //$nav_bar.css({top:$win.height()+$win.scrollTop()-$top},50);
		$ittop=$win.height()+$win.scrollTop()-$top;
		
		if (window.ActiveXObject) {
			$nav_bar.css({
			position: "absolute",
			top: $ittop
		});
		}
    });
	$win.resize(function(){
		$nav_bar.css({top:$win.height()+$win.scrollTop()-$top});
	})
	if (window.ActiveXObject) {
		$nav_bar.css({top:$win.height()-$top,position:'absolute'});
	}else{
		$nav_bar.css({top:$win.height()-$top});
		}
});

/*arrowhead*/
$(document).ready(function(){
      if($(".scroll_btn").size()>0){
		var $scroll_btn   = $(".scroll_btn"),
		$window    = $(window),
		offset     = $scroll_btn.offset(),
		top = 40;
		$window.scroll(function() {
		    if ($window.scrollTop() > offset.top) {
		        $scroll_btn.stop().animate({
		            top: $window.scrollTop() - offset.top + top+'px'
		        });
		    } else {
		        $scroll_btn.stop().animate({
		            top: 40
		        });
		    }
		});
		$('.scroll_top').bind('click', function() {
			scrollTo(false);
			return false;
		});

		$('.scroll_down').bind('click', function() {
			scrollTo(true);
			return false;
		});
	}
});

function a_toggle(id) {
	$("#"+id).toggle()
}
