// Tiny Scrollbar: A lightweight jQuery plugin (function($){$.tiny=$.tiny||{};$.tiny.scrollbar={options:{axis:'y',wheel:40,scroll:true,size:'auto',sizethumb:'auto'}};$.fn.tinyscrollbar=function(options){var options=$.extend({},$.tiny.scrollbar.options,options);this.each(function(){$(this).data('tsb',new Scrollbar($(this),options));});return this;};$.fn.tinyscrollbar_update=function(sScroll){return $(this).data('tsb').update(sScroll);};function Scrollbar(root,options){var oSelf=this;var oWrapper=root;var oViewport={obj:$('.viewport',root)};var oContent={obj:$('.overview',root)};var oScrollbar={obj:$('.scrollbar',root)};var oTrack={obj:$('.track',oScrollbar.obj)};var oThumb={obj:$('.thumb',oScrollbar.obj)};var sAxis=options.axis=='x',sDirection=sAxis?'left':'top',sSize=sAxis?'Width':'Height';var iScroll,iPosition={start:0,now:0},iMouse={};function initialize(){oSelf.update();setEvents();return oSelf;} this.update=function(sScroll){oViewport[options.axis]=oViewport.obj[0]['offset'+sSize];oContent[options.axis]=oContent.obj[0]['scroll'+sSize];oContent.ratio=oViewport[options.axis]/oContent[options.axis];oScrollbar.obj.toggleClass('disable',oContent.ratio>=1);oTrack[options.axis]=options.size=='auto'?oViewport[options.axis]:options.size;oThumb[options.axis]=Math.min(oTrack[options.axis],Math.max(0,(options.sizethumb=='auto'?(oTrack[options.axis]*oContent.ratio):options.sizethumb)));oScrollbar.ratio=options.sizethumb=='auto'?(oContent[options.axis]/oTrack[options.axis]):(oContent[options.axis]-oViewport[options.axis])/(oTrack[options.axis]-oThumb[options.axis]);iScroll=(sScroll=='relative'&&oContent.ratio<=1)?Math.min((oContent[options.axis]-oViewport[options.axis]),Math.max(0,iScroll)):0;iScroll=(sScroll=='bottom'&&oContent.ratio<=1)?(oContent[options.axis]-oViewport[options.axis]):isNaN(parseInt(sScroll))?iScroll:parseInt(sScroll);setSize();};function setSize(){oThumb.obj.css(sDirection,iScroll/oScrollbar.ratio);oContent.obj.css(sDirection,-iScroll);iMouse['start']=oThumb.obj.offset()[sDirection];var sCssSize=sSize.toLowerCase();oScrollbar.obj.css(sCssSize,oTrack[options.axis]);oTrack.obj.css(sCssSize,oTrack[options.axis]);oThumb.obj.css(sCssSize,oThumb[options.axis]);};function setEvents(){oThumb.obj.bind('mousedown',start);oThumb.obj[0].ontouchstart=function(oEvent){oEvent.preventDefault();oThumb.obj.unbind('mousedown');start(oEvent.touches[0]);return false;};oTrack.obj.bind('mouseup',drag);if(options.scroll&&this.addEventListener){oWrapper[0].addEventListener('DOMMouseScroll',wheel,false);oWrapper[0].addEventListener('mousewheel',wheel,false);} else if(options.scroll){oWrapper[0].onmousewheel=wheel;}};function start(oEvent){iMouse.start=sAxis?oEvent.pageX:oEvent.pageY;var oThumbDir=parseInt(oThumb.obj.css(sDirection));iPosition.start=oThumbDir=='auto'?0:oThumbDir;$(document).bind('mousemove',drag);document.ontouchmove=function(oEvent){$(document).unbind('mousemove');drag(oEvent.touches[0]);};$(document).bind('mouseup',end);oThumb.obj.bind('mouseup',end);oThumb.obj[0].ontouchend=document.ontouchend=function(oEvent){$(document).unbind('mouseup');oThumb.obj.unbind('mouseup');end(oEvent.touches[0]);};return false;};function wheel(oEvent){if(!(oContent.ratio>=1)){oEvent=$.event.fix(oEvent||window.event);var iDelta=oEvent.wheelDelta?oEvent.wheelDelta/120:-oEvent.detail/3;iScroll-=iDelta*options.wheel;iScroll=Math.min((oContent[options.axis]-oViewport[options.axis]),Math.max(0,iScroll));oThumb.obj.css(sDirection,iScroll/oScrollbar.ratio);oContent.obj.css(sDirection,-iScroll);oEvent.preventDefault();};};function end(oEvent){$(document).unbind('mousemove',drag);$(document).unbind('mouseup',end);oThumb.obj.unbind('mouseup',end);document.ontouchmove=oThumb.obj[0].ontouchend=document.ontouchend=null;return false;};function drag(oEvent){if(!(oContent.ratio>=1)){iPosition.now=Math.min((oTrack[options.axis]-oThumb[options.axis]),Math.max(0,(iPosition.start+((sAxis?oEvent.pageX:oEvent.pageY)-iMouse.start))));iScroll=iPosition.now*oScrollbar.ratio;oContent.obj.css(sDirection,-iScroll);oThumb.obj.css(sDirection,iPosition.now);} return false;};return initialize();};})(jQuery); (function() { var _AJAXING = false; jQuery(document).ajaxSend(function(){ _AJAXING = true; }); jQuery(document).ajaxComplete(function(){ _AJAXING = false; }); function isBlank(str){ return (typeof(str) == 'undefined' || str == null || $.trim(str) == ''); } function isEmail(str){ var re = new RegExp('^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]{2,4}$'); return (str.search(re) != -1); } function isPhone(str){ var re = new RegExp('^[0-9\\s\\(\\)\\+\\-]{5,}$'); return (str.search(re) != -1); } function isNum(str){ var re = new RegExp('^[0-9]+$'); return (str.search(re) != -1); } function initLayerMask() { $('
', { 'id': 'layerMask' , 'html': ' ' , 'click': function(event) { event.preventDefault(); } }).appendTo('body'); } function showLayerMask() { $('#layerMask').css('opacity', 0.92).show(0); } function hideLayerMask() { $('#layerMask').hide(0); } function initHomeRotating() { var index = 0; var elements = $('#homePanel li'); if (elements.length <= 1) { return; } setTimeout(slideIt, 3000); function slideIt() { var hideElement = $(elements[index]); hideElement.fadeOut(2000); index++; if (index >= elements.length) { index = 0; } var showElement = $(elements[index]); showElement.fadeIn(2000); setTimeout(slideIt, 10000); } } function initBrandList() { $('#brandList li[class!=details] a').mouseenter(function(event){ $(this).find('img:first-child').stop(true, true).fadeOut(500); }).mouseleave(function(event){ $(this).find('img:first-child').stop(true, true).fadeIn(500); }); } function initDealerList() { // slider var dir = 0; var timeOutInterval = null; $('#brandScrollDown').mouseover(function(event) { dir = 1; slideIt(); }).mouseout(function(event) { dir = 0; clearTimeout(timeOutInterval); }); $('#brandScrollUp').mouseover(function(event) { dir = -1; slideIt(); }).mouseout(function(event) { dir = 0; clearTimeout(timeOutInterval); }); $('#dealerList ul').scrollTop(0); function slideIt() { if (dir == 0) { clearTimeout(timeOutInterval); return; } $('#dealerList ul').scrollTop(Number($('#dealerList ul').scrollTop()) + dir * 20); timeOutInterval = setTimeout(slideIt, 40); } // jumper $('#brandLogoList a').click(function(event) { event.preventDefault(); var anchor = this.href.toString().split('#')[1]; if (typeof(anchor) == 'undefined' || anchor == null || $.trim(anchor) == '') { return; } $('#dealerList ul').animate({ 'scrollTop': $('#' + anchor).offset().top - $('#dealerList ul').offset().top + $('#dealerList ul').scrollTop() }); }); } function initCopyButton() { if ($.flash.available && $.flash.version && $.flash.version.major >= 10) { // add copy button to input $('input.copyInput').each(function(index) { var span = $(this).wrap('').parent(); span.attr('id', 'copyBtn' + index).css({ 'display': 'block' , 'float': $(this).css('float') , 'width': $(this).outerWidth() , 'height': $(this).outerHeight() }); var copyHolder = $('', { 'id': 'copyBtn' + index , 'class': 'copyBtn' }).appendTo(span); $(this).css({ 'width': $(this).outerWidth() - 100 , 'float': 'left' }); $(copyHolder).flash({ 'swf': '/staging/templates/newest/flashpub/copy.swf' , 'width': '100%' , 'height': '100%' , 'wmode': 'transparent' , 'flashvars': { 'clipboardURL': $(this).attr('value') , 'targetBtn': $(copyHolder).attr('id') } }); }); } window.clipBoardSet = function(str) { alert('Đường dẫn chia sẽ đã được lưu vào bộ nhớ đệm (clipboard)' + '\n' + str); } } function initMediaList() { var items = $('#mediaList li'); if (items.length <= 4) { $('#scrollPrev').empty(); $('#scrollNext').empty(); return; } $('#mediaList li:last-child').css('margin', 0); $('#mediaList ul').css('width', items.length * 181 - 5); $('#mediaList li a').mouseenter(function(event) { // var playBtn = $(this).find('span.play'); // if (playBtn.length == 0) { // $('', { // 'class': 'play' // }).appendTo(this); // } else { // playBtn.show(0); // } }).mouseleave(function(event) { //$(this).find('span.play').hide(0); }); $('#scrollPrev a').click(function(event) { event.preventDefault(); scrollIt(-1); }); $('#scrollNext a').click(function(event) { event.preventDefault(); scrollIt(1); }); $('#mediaList div').scrollLeft(0); function scrollIt(dir) { $('#mediaList div').stop(true, true).animate({ 'scrollLeft': '+='+(dir * 181) }, 500); } } function initEventCalendar() { // slider var dir = 0; var timeOutInterval = null; $('#eventBottom a').mouseover(function(event) { dir = 1; slideCalendar(); }).mouseout(function(event) { dir = 0; clearTimeout(timeOutInterval); }); $('#eventTop a').mouseover(function(event) { dir = -1; slideCalendar(); }).mouseout(function(event) { dir = 0; clearTimeout(timeOutInterval); }); $('#eventCalendar dl').scrollTop(0); function slideCalendar() { if (dir == 0) { clearTimeout(timeOutInterval); return; } $('#eventCalendar dl').scrollTop(Number($('#eventCalendar dl').scrollTop()) + dir * 10); timeOutInterval = setTimeout(slideCalendar, 40); } } function initComments() { $('#commentList ul, #aboutMe .aboutMeIntro').each(function(index) { var scrollbar = $('
', { 'id': 'scrollbar' + index , 'class': 'scrollbarArea' , 'html': '
' }).insertBefore(this); $(this).addClass('overview').appendTo(scrollbar.find('div.viewport')); scrollbar.tinyscrollbar(); }); $('#shareForm').submit(function(event) { if (isBlank(this.comment.value)) { event.preventDefault(); alert('Xin vui lòng lời bình!'); this.comment.focus(); return; } }); } function initRegistration() { $('#userAgreement div').each(function(index) { var scrollbar = $('
', { 'id': 'scrollbar' + index , 'class': 'scrollbarArea' , 'html': '
' }).insertBefore(this); $(this).addClass('overview').appendTo(scrollbar.find('div.viewport')); scrollbar.tinyscrollbar(); }); } function initRobotHome() { $('#robotCampaign').scrollTop(578); /*$('#joinRobot').click(function(event) { if (!$(this).hasClass('loggedIn')) { event.preventDefault(); $('#robotCampaign').stop(true, true).animate({ 'scrollTop': 0 }, 700); } });*/ $('#cancelReg, #cancelSignin').click(function(event) { event.preventDefault(); $('#robotCampaign').stop(true, true).animate({ 'scrollTop': 578 }, 700); }); $('#signinRobot').click(function(event) { event.preventDefault(); $('#robotCampaign').stop(true, true).animate({ 'scrollTop': 2 * 578 }, 700); }); $('#registerForm input[name=address]').focus(function(event) { if ($.trim($(this).val()) == 'Số nhà') { $(this).val(''); } }).blur(function(event) { if (isBlank($(this).val())) { $(this).val('Số nhà'); } }); $('#registerForm input[name=street]').focus(function(event) { if ($.trim($(this).val()) == 'Đường') { $(this).val(''); } }).blur(function(event) { if (isBlank($(this).val())) { $(this).val('Đường'); } }); $('#registerForm input[name=ward]').focus(function(event) { if ($.trim($(this).val()) == 'Phường') { $(this).val(''); } }).blur(function(event) { if (isBlank($(this).val())) { $(this).val('Phường'); } }); $('#registerForm input[name=district]').focus(function(event) { if ($.trim($(this).val()) == 'Quận') { $(this).val(''); } }).blur(function(event) { if (isBlank($(this).val())) { $(this).val('Quận'); } }); $('#registerForm input[name=city]').focus(function(event) { if ($.trim($(this).val()) == 'Thành phố') { $(this).val(''); } }).blur(function(event) { if (isBlank($(this).val())) { $(this).val('Thành phố'); } }); $('#registerForm').submit(function(event) { if (isBlank(this.fullname.value)) { event.preventDefault(); alert('Xin vui lòng nhập tên!'); this.fullname.focus(); return; } if (isBlank(this.email.value)) { event.preventDefault(); alert('Xin vui lòng nhập email!'); this.email.focus(); return; } if (!isEmail(this.email.value)) { event.preventDefault(); alert('Địa chỉ email không hợp lệ!'); this.email.focus(); return; } if (isBlank(this.password.value)) { event.preventDefault(); alert('Xin vui lòng nhập mật khẩu!'); this.password.focus(); return; } if ($.trim(this.password.value).length < 6) { event.preventDefault(); alert('Mật khẩu phải có ít nhất 6 ký tự!'); this.password.focus(); return; } if (isBlank(this.phone.value)) { event.preventDefault(); alert('Xin vui lòng nhập số điện thoại!'); this.phone.focus(); return; } if (!isPhone(this.phone.value)) { event.preventDefault(); alert('Số điện thoại không hợp lệ!'); this.phone.focus(); return; } if (isBlank(this.address.value) || $.trim(this.address.value) == 'Số nhà') { event.preventDefault(); alert('Xin vui lòng nhập số nhà!'); this.address.focus(); return; } if (isBlank(this.street.value) || $.trim(this.street.value) == 'Đường') { event.preventDefault(); alert('Xin vui lòng nhập tên đường!'); this.street.focus(); return; } if (isBlank(this.ward.value) || $.trim(this.ward.value) == 'Phường') { event.preventDefault(); alert('Xin vui lòng nhập phường!'); this.ward.focus(); return; } if (isBlank(this.district.value) || $.trim(this.district.value) == 'Quận') { event.preventDefault(); alert('Xin vui lòng nhập quận!'); this.district.focus(); return; } if (isBlank(this.city.value) || $.trim(this.city.value) == 'Thành phố') { event.preventDefault(); alert('Xin vui lòng nhập thành phố!'); this.city.focus(); return; } if ($('#agree').length != 0 && $('#agree').attr('checked') != 'checked') { event.preventDefault(); alert('Bạn phải đồng ý với thể lệ & điều kiện!'); $('#agree').focus(); return; } }); } function initSigninForm() { $('#signinForm').submit(function(event) { if (isBlank(this.email.value)) { event.preventDefault(); alert('Xin vui lòng nhập email!'); this.email.focus(); return; } if (!isEmail(this.email.value)) { event.preventDefault(); alert('Địa chỉ email không hợp lệ!'); this.email.focus(); return; } if (isBlank(this.password.value)) { event.preventDefault(); alert('Xin vui lòng nhập mật khẩu!'); this.password.focus(); return; } }); } function initVoteButtons() { /* xoa doan duoi khi da chinh sua xong */ //alert('Vui long mo site.js ra de xem them chi tiet ve ham binh chon!'); /* Moi khi vote button duoc click - Se call ajax den link trong vote button & truyen them email nguoi binh chon - Tra ve 0: da vote. Alert ra thong bao. - Tra ve num: total vote cho robot nay. Se update so vote truc tiep len trang. CHU Y: - Check IP. Mot IP chi duoc vote cho 1 robot 1 lan duy nhat. Neu click nhieu lan, tra ve 0. */ var voteURL, likeBtn; $('a.voteBtn').click(function(event) { if ($('.participate').length > 0) { return; } event.preventDefault(); if (_AJAXING) { return; } likeBtn = $(this).next(); voteURL = $(this).attr('href'); var popup = $('#emailPopup'); if (popup.length == 0) { popup = $('
', { 'id': 'emailPopup' , 'method': 'POST' , 'action': 'index.php?view=gallery&option=com_joomgallery&task=vote' , 'html': '

Nhập email

captcha

Nhập mã

' , 'submit': function(event) { event.preventDefault(); if (isBlank(this.email.value)) { alert('Xin vui lòng nhập email!'); this.email.focus(); return; } if (!isEmail(this.email.value)) { alert('Địa chỉ email không hợp lệ!'); this.email.focus(); return; } if (isBlank(this.captcha.value)) { alert('Xin vui lòng nhập captcha!'); this.email.focus(); return; } postVote($.trim(this.email.value),$.trim(this.captcha.value)); $('#emailPopup').hide(0); hideLayerMask(); } }).appendTo('body'); $('', { 'href': '#' , 'class': 'closeBtn' , 'css': { 'position': 'fixed' , 'top': '183px' , 'left': '50%' , 'margin-left': '220px' , 'z-index': 1001 } , 'click': function(event) { event.preventDefault(); $('#emailPopup').hide(0); hideLayerMask(); } }).appendTo(popup); } if ($('#content').hasClass('postedEmail')) { postVote(); } else { popup.show(0); showLayerMask(); } }); function postVote(email,captcha) { $.ajax({ 'url': voteURL , 'type': 'GET' , 'data': ((email != null) ? '&captcha='+captcha+'&email=' + email : '') , 'dataType': 'text' , 'success': function(msg){ $('#content').addClass('postedEmail') if (msg !=""){ if (msg.length <=70){ if (msg=='Ban khong duoc quyen binh chon lai' || msg == 'Ban chi khong the binh chon hinh cua chinh ban.'){ alert(msg); document.getElementById('imgcaptcha').src ='http://www.taiwanexcellence.com.vn/index.php?option=com_joomgallery&task=getcaptcha&aaaa='+Math.floor(Math.random()*101); $('#emailPopup').hide(0); }else{ alert(msg); document.getElementById('imgcaptcha').src ='http://www.taiwanexcellence.com.vn/index.php?option=com_joomgallery&task=getcaptcha&aaaa='+Math.floor(Math.random()*101); $('#emailPopup').show(0); } } }else{ //$('.likeInfo').text(msg); } //if (msg !="" && msg.length <=50){ //} } }).responseText;; } } function initAddFooter() { $('#hoanlong').flash({ 'swf': 'flashpub/hoanlong.swf' , 'height': 34 , 'width': 170 , 'hasVersion': 10 , 'wmode': 'transparent' , 'menu': 'false' }); } $(document).ready(function() { initAddFooter(); initLayerMask(); initBrandList(); initDealerList(); initCopyButton(); initMediaList(); initEventCalendar(); initComments(); initRegistration(); initRobotHome(); initSigninForm(); initVoteButtons(); }); $(window).load(function(){ initHomeRotating(); }); })();