/*
* BGF Front-End Javascript Library
* @Date : 2014-03-11
* @Author : Jaeho Sim(bvlgaricl@aintlab.com)
*
**/
// Console for IE
if (typeof console === "undefined" || typeof console.log === "undefined") { console = {}; console.log = function(msg) { alert(msg);};}
// ieCheck
BGF_Browser = function(browserName) {
var htmlClass = $HTML.attr('class');
if ( htmlClass.indexOf(browserName) != -1 ) {
return true;
} else {
return false;
}
}
// cookies
function CookieCreate(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function CookieCreateInstant(cookieName, cookieValue) {
document.cookie = cookieName + "=" + escape(cookieValue) + "; path=/;";
}
function CookieRead(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function CookieErase(name) {
createCookie(name,"",-1);
}
// mobile Check
function BGF_isMobile() {
return (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino|android|ipad|playbook|silk/i.test(navigator.userAgent||navigator.vendor||window.opera)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test((navigator.userAgent||navigator.vendor||window.opera).substr(0,4)))
}
// FAQ
function BGF_FAQ() {
var Wrapper = $('.FAQ')
, Question = Wrapper.find('tr.Question')
, Trigger = Question.find('a')
, Answer = Wrapper.find('tr.Answer td');
Question.each(function() {
var This = $(this)
, ThisAnswer = $(this).next().find('td');
$(this).find('a').on({
click : function() {
Answer.hide();
ThisAnswer.show();
Question.removeClass('Open');
This.addClass('Open');
return false;
}
});
});
}
// PrettySelect
function BGF_PrettySelect(ObjectName) {
var Object = $('select').filter(ObjectName);
Object.each(function(oi) {
// check
var OriginElement = $(this)
, OriginID = OriginElement.attr('id');
// check exist
if ( OriginElement.prev('.PrettySelect').length ) {
OriginElement.prev('.PrettySelect').remove();
}
var OriginElementOption = OriginElement.find('option')
, OriginElementWidth = OriginElement.width()
, NewSelectElement = $('
').insertBefore(OriginElement)
, NewSelectElementHTML = '
'
+ ''
, OptionHTML = ''
, SelectedOptionElement, SelectedOptionElementTrigger, SelectedOptionElementIco, SelectedOptionElementText, OptionListElement, OptionTriggerElement, OptionSelectedElement
, BodyHeight, NewSelectElementTop, NewSelectElementHeight, OptionListElementHeight, NewSelectElementLimit, NewSelectElementWidth
, MotionSpeed = 100
, OptionElement
, IsUpside = false;
// set HTML to _NewSelectElement
NewSelectElement.html(NewSelectElementHTML).addClass('PrettySelect'+(oi+1)).attr('id','Pretty_'+OriginID);
// set Variables
SelectedOptionElement = NewSelectElement.find('p.selected');
SelectedOptionElementTrigger = SelectedOptionElement.children('a');
SelectedOptionElementIco = SelectedOptionElementTrigger.find('.ico');
SelectedOptionElementText = SelectedOptionElement.find('span.text')
OptionListElement = NewSelectElement.find('ul.optionList');
// create listItem
OriginElementOption.each(function() {
var ThisText = $(this).text();
if ( $(this).is(':selected') ) {
OptionHTML += '' + ThisText + '';
} else {
OptionHTML += '' + ThisText +'';
}
});
OptionListElement.html(OptionHTML);
OptionElement = OptionListElement.find('li');
OptionElement.first().addClass('first');
OptionElement.last().addClass('last');
OptionTriggerElement = OptionElement.find('a');
OptionSelectedElement = OptionElement.filter('.selected').find('a')
SelectedOptionElementText.text(OptionSelectedElement.text());
// CalcurateWidth
Calcurate();
// Binding
Binding();
DocumentBinding();
// CalcurateWidth
function Calcurate() {
OptionListElement.show();
BodyHeight = $('body').height()
NewSelectElementTop = parseInt(NewSelectElement.offset().top, 10)
NewSelectElementHeight = parseInt(NewSelectElement.height(), 10)
OptionListElementHeight = parseInt(OptionListElement.height(), 10)
NewSelectElementLimit = NewSelectElementTop + NewSelectElementHeight + OptionListElementHeight;
NewSelectElementWidth = OriginElementWidth + SelectedOptionElementIco.width();
//if ( $('html').hasClass('safari') ) _NewSelectElementWidth += _SelectedOptionElementIco.width();
if ( BodyHeight < NewSelectElementLimit ) {
NewSelectElement.addClass('upSide');
IsUpside = true;
}
NewSelectElement.width(NewSelectElementWidth);
OptionListElement.hide();
OriginElement.hide();
}
// _Binding
function Binding() {
// open _OptionListElement
SelectedOptionElementTrigger.on({
click : function() {
if ( OptionListElement.is(':hidden') ) {
ShowOptionListElement();
} else {
HideOptionListElement();
}
return false;
}
});
// option click
OptionTriggerElement.each(function(i) {
var ThisValue = $(this).text();
$(this).on({
click : function() {
OptionElement.removeClass('selected');
$(this).parent().addClass('selected');
SelectedOptionElementText.text(ThisValue);
ReturnValueToOriginElement(i);
HideOptionListElement();
return false;
}
});
});
}
// show OptionListElement
function ShowOptionListElement() {
var AllSelectELement = $('.PrettySelect');
AllSelectELement.find('p.selected').find('>a').removeClass('open');
SelectedOptionElementTrigger.addClass('open');
AllSelectELement.not(NewSelectElement).each(function() {
var ThisOptionListElement = $(this).find('.optionList');
if ( ThisOptionListElement.is(':visible') ) {
ThisOptionListElement.hide();
}
});
OptionListElement.show();
}
// hide OptionListElement
function HideOptionListElement() {
SelectedOptionElementTrigger.removeClass('open');
OptionListElement.hide();
}
// return value to _OriginElement
function ReturnValueToOriginElement(order) {
OriginElementOption.removeAttr('selected');
OriginElementOption.eq(order).attr('selected','selected');
OriginElement.change();
}
// document _Binding
function DocumentBinding() {
$(document).on({
click : function(e) {
var e = e || window.event
, Target = $(e.relatedTarget);
if ( !Target.parents('.PrettySelect').length ) {
HideOptionListElement();
}
}
});
}
});
}
// FontSizeControl
function FontSizeControl() {
var FontWrap = $('.FontSize')
, Smaller = FontWrap.find('a').eq(0)
, Larger = FontWrap.find('a').eq(1)
, Content = FontWrap.parents('.ContainerInner').get(0);
//Specify affected tags. Add or remove from list:
var tgs = new Array( 'div','th','td','tr','a','p','li','span','strong','h1','h2','h3','h4','h5','h6','dd','dt','table');
//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 2;
function ts( trgt,inc ) {
if (!document.getElementById) return
var d = document,cEl = null,sz = startSz,i,j,cTags;
sz += inc;
if ( sz < 0 ) sz = 0;
if ( sz > 6 ) sz = 6;
startSz = sz;
cEl = trgt;
cEl.style.fontSize = szs[ sz ];
for ( i = 0 ; i < tgs.length ; i++ ) {
cTags = cEl.getElementsByTagName( tgs[ i ] );
for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
}
}
Smaller.on({
click : function() {
ts(Content,-1);
}
});
Larger.on({
click : function() {
ts(Content,1);
}
});
}
// IndexVisual
function IndexVisual() {
var Wrap = $('#IndexVisual')
, FlashPlayer = Wrap.find('.FlashPlayer')
, VisWrap = Wrap.find('.VisWrap')
, Visual = VisWrap.find('.Visual')
, ButtonArea = Wrap.find('.ButtonArea')
, SloganWrap = ButtonArea.find('.Slogan')
, Slogan = SloganWrap.find('ul')
, BtnPrev = ButtonArea.find('.Btn.Prev')
, BtnNext = ButtonArea.find('.Btn.Next')
, BtnPlay = ButtonArea.find('.Play')
, BtnPause = ButtonArea.find('.Pause')
, SloganHeight = SloganWrap.height()
, MovingHeight = Wrap.height()
, VisualHTML = []
, CurrentIdx = 0
, IsAutoRolling = false
, IsRolling = false
, RollDelay = 5000
, RollTimeout = null
, RollTimer = null;
Initialize();
// Initialize
function Initialize() {
Visual.each(function(i) {
var Shape = $(this).find('.Shape')
, Title = $(this).find('.Title');
VisualHTML[i] = $(this).html();
Shape.each(function() {
var ThisTop = $(this).css('top')
, ThisLeft = $(this).css('left');
$(this).attr({
'data-left' : ThisLeft
, 'data-top' : ThisTop
});
$(this).css({
left : 608
, top : 180
, opacity: 0
});
Title.css('opacity', 0);
});
});
Loading();
}
// Loading
function Loading() {
TweenMax.to(VisWrap, 0.3, { delay: 0.3, autoAlpha : 1 });
TweenMax.to(ButtonArea, 0.3, { delay : 0.3, autoAlpha : 1, onComplete : function() {
//AutoRoll();
Binding();
Motion();
}});
}
// InitState
function InitState(idx, callback) {
var InitVisual = Visual.eq(idx);
InitVisual.html(VisualHTML[idx]);
var InitShape = InitVisual.find('.Shape')
, InitTitle = InitVisual.find('.Title');
InitShape.each(function() {
var ThisTop = $(this).css('top')
, ThisLeft = $(this).css('left');
$(this).attr({
'data-left' : ThisLeft
, 'data-top' : ThisTop
});
$(this).css({
left : 608
, top : 180
, opacity: 0
});
});
InitTitle.css('opacity', 0);
setTimeout(callback, 100);
}
// MotionShape
function Motion() {
var Shape = Visual.eq(CurrentIdx).find('.Shape')
, Title = Visual.eq(CurrentIdx).find('.Title');
TweenMax.to(Title, 0.5, { autoAlpha : 1, onComplete : function() {
Shape.each(function(i) {
var ThisTop = $(this).attr('data-top')
, ThisLeft = $(this).attr('data-left');
TweenMax.to($(this), 0.7, { delay : i * 0.07, left : ThisLeft, top : ThisTop, opacity : 1, ease : Power2.easeOut, onComplete : function() {
}});
});
}});
//setTimeout(ShapeDrift, 7000);
}
// AutoRoll
function AutoRoll() {
ClearTimeout();
if ( RollTimer ) RollTimer = null;
IsAutoRolling = true;
RollTimer = setInterval(Rolling, RollDelay);
}
// Biding
function Binding() {
BtnNext.on({
click : function() {
if ( !IsRolling ) {
IsRolling = true;
ClearInterval();
Rolling();
RollTimeout = setTimeout(function() {
if ( IsAutoRolling ) {
AutoRoll();
}
}, 1000);
}
}
});
BtnPrev.on({
click : function() {
if ( !IsRolling ) {
IsRolling = true;
ClearInterval();
RollingReverse();
RollTimeout = setTimeout(function() {
if ( IsAutoRolling ) {
AutoRoll();
}
}, 1000);
}
}
});
BtnPlay.on({
click : function() {
if ( !IsAutoRolling ) {
IsAutoRolling = true;
AutoRoll();
}
}
});
BtnPause.on({
click : function() {
if ( IsAutoRolling ) {
IsAutoRolling = false;
clearInterval(RollTimer);
RollTimer = null;
}
}
});
}
// ClearTime
function ClearInterval() {
clearInterval(RollTimer);
RollTimer = null;
}
function ClearTimeout() {
clearInterval(RollTimeout);
RollTimeout = null;
}
// Rolling
function Rolling() {
CurrentIdx += 1;
if ( CurrentIdx == Visual.length ) CurrentIdx = 0;
VisualMove();
}
// RollingReverse
function RollingReverse() {
CurrentIdx -= 1;
if ( CurrentIdx < 0 ) CurrentIdx = Visual.length - 1;
VisualMove();
}
// VisualMove
function VisualMove() {
var CurrentTop = - ( CurrentIdx * MovingHeight)
, CurrentTopSlogan = - ( CurrentIdx * SloganHeight );
InitState(CurrentIdx, function() {
TweenMax.to(VisWrap, 0.45, { top : CurrentTop, ease : Power2.easeIn, onComplete : function() {
IsRolling = false;
Motion();
}});
TweenMax.to(Slogan, 0.45, { marginTop : CurrentTopSlogan, ease : Power2.easeIn });
});
}
// ShapeDrift
function ShapeDrift() {
/*
var CurrentVisual = Visual.eq(CurrentIdx)
, Top = 0
, Left = 0
, MovingX = 1
, MovingY = 1;
CurrentVisual.on({
mousemove : function(e) {
var Xpos = e.pageX / 10
, Ypos = e.pageY / 10;
MoveShape(-Xpos, -Ypos);
}
});
*/
}
// Move Shape
function MoveShape(x, y) {
/*
var Shape = Visual.eq(CurrentIdx).find('.Shape');
Shape.each(function() {
var ThisLeft = parseInt($(this).attr('data-left'), 10)
, ThisTop = parseInt($(this).attr('data-top'), 10)
, Level = parseInt($(this).attr('data-level'), 10);
x = x + ( x * (Level/10));
y = y + ( y * (Level/10));
TweenMax.to($(this), 0.2, { left : ThisLeft + x + 200, top : ThisTop + y + 60, ease : Power2.easeOut });
});
*/
}
}