var opt = {
	agent : navigator.userAgent.toLowerCase(),
	browser : {
		i6 : 'msie 6.0',
		i7 : 'msie 7.0',
		i8 : 'msie 8.0',
		ff : 'firefox',
		op : 'opera',
		cr : 'chrome',
		sf : 'safari'
	},
	speed : {
		ms3: 300,
		ms4: 400,
		ms5: 500,
		ms6: 600,
		ms7: 700,
		ms8: 800,
		ms9: 900,
		ms10: 1000,
		ms11: 1100,
		ms12: 1200,
		ms13: 1300,
		ms14: 1400,
		ms15: 1500,
		ms16: 1600,
		ms20: 2000,
		ms25: 2500,
		ms30: 3000,
		ms50: 5000
	}
};


$(window).load(function() {
	bestBanner();
});


function rolling(num, beforeID, currentID, beforePos, beforePos2, currentPos, currentPos2 ) {
	$(':animated').stop(false, true);
	if(!isVideo) pause();

	var $ready = $('.ready', $('#bestBanner'));
	var $bestNavLi = $('#bestNav > li');

	var $beforeID = $(beforeID);
	var $currentID = $(currentID);

	$ready.find('.bestPhoto').css({'opacity': .5 });
	$ready.find('.bestTitle1').css({'opacity': .5 });
	$ready.find('.bestTitle2').css({'opacity': .5 });
	$ready.find('.bestPara').css({'opacity': .5 });

	if($currentID.hasClass('ready')) {

		$currentID.find('.bestPhoto').css({'left': currentPos+'px', 'opacity': 1 }, opt.speed.ms9, 'easeOutCubic');
		$currentID.find('.bestTitle1').css({'right': currentPos2+'px', 'opacity': 1 }, opt.speed.ms7, 'easeOutCubic');
		$currentID.find('.bestTitle2').css({'right': currentPos2+'px', 'opacity': 1 }, opt.speed.ms8, 'easeOutCubic');
		$currentID.find('.bestPara').css({'right': currentPos2+'px', 'opacity': 1 }, opt.speed.ms6, 'easeOutCubic');
		$currentID.removeClass('ready').addClass('active');

		$beforeID.find('.bestPhoto').css({'left': beforePos+'px'}, opt.speed.ms3, 'easeOutCubic', function() {
			$beforeID.find('.bestPhoto').css({'left': beforePos2+'px', 'opacity': .5 });
		});
		$beforeID.find('.bestTitle1').css({'right': beforePos2+'px'}, opt.speed.ms3, 'easeOutCubic', function() {
			$beforeID.find('.bestTitle1').css({'right': beforePos+'px', 'opacity': .5 });
		});
		$beforeID.find('.bestTitle2').css({'right': beforePos2+'px'}, opt.speed.ms3, 'easeOutCubic', function() {
			$beforeID.find('.bestTitle2').css({'right': beforePos+'px', 'opacity': .5 });
		});
		$beforeID.find('.bestPara').css({'right': beforePos2+'px'}, opt.speed.ms3, 'easeOutCubic', function() {
			$beforeID.find('.bestPara').css({'right': beforePos+'px', 'opacity': .5 });
		});
		$beforeID.removeClass('active').addClass('ready');

	}

	$bestNavLi.each(function(idx) {
		$bestNavLi.eq(idx).children('img:first').addClass('hidden');
		$bestNavLi.eq(idx).children('img:last').removeClass('hidden');
	});
	$bestNavLi.eq(num).children('img:first').removeClass('hidden');
	$bestNavLi.eq(num).children('img:last').addClass('hidden');

}


function pause() {
	ytplayer1 = document.getElementById("myytplayer1");
	ytplayer2 = document.getElementById("myytplayer2");
	ytplayer3 = document.getElementById("myytplayer3");
	ytplayer4 = document.getElementById("myytplayer4");
	ytplayer5 = document.getElementById("myytplayer5");
}

function activeObjViewHide(obj, flag,classname) {
	var from = flag.split('>')[0];
	var to = flag.split('>')[1];
	var $from = $(obj).find('.'+from);
	var $to = $(obj).find('.'+to);
	$from.addClass('hidden');
	$to.removeClass('hidden');
}

function activeAllObjViewHide($obj, flag, classname) {
	$obj.each(function(idx) {
		activeObjViewHide($obj.eq(idx), flag, classname);
	});
}

//devices
var isMobiles = function() {
	var devices = new Array('iphone','ipod','ipad','blackberry','android','windows ce','lg','mot','samsung','sonyericsson');
	for(var i=0; i<devices.length; i++) {
		if(opt.agent.indexOf(devices[i]) != -1) {
			return true;
		}
	}
};