/*
* jquery turunto slide
*/
(function() {
$.fn.extend({
ts: function(opt) {
var ts = {};
ts.elem = this;
ts.def = {borderW: 20,underH: 50,speed: 500,type: 2,auto: false, timer: 6000};
ts.set = $.extend(ts.def, opt);
if(navigator.userAgent.indexOf('MSIE') != -1) ts.iebrows = true;
if(navigator.userAgent.indexOf('iPhone') != -1) ts.ibrows = true;
$(this).click(function() {
ts.group = this.rel != 'ts';
ts.loadFlag = false;
if(ts.group) groupCreate(this);
elemCreate(this);
getOffset();
$('#tsOverlay').animate({opacity: 0.8},'slow');
$('#tsImgBody').fadeIn('slow');
if(ts.group) $('#tsTitle').get(0).innerHTML = ts.array[ts.count][1] + '
' + (ts.count + 1) + '/' + ts.array.length;
if(!$('#tsCurrentImg').get(0)) return;
$('#tsCurrentImg').get(0).onload = function() {
clearInterval(ts.timer);
$('#tsLoading').css('display','none');
getWH(this);
effectIn();
if(ts.group && ts.set.auto) ts.slideTimer = setInterval(function(){$('#tsNext').trigger('click')}, ts.set.timer);
};
outEvent();
//-----------group slide-----------------
$('#tsNext, #tsPrev').click(function(e) {
e.stopPropagation();
if(!ts.loadFlag) return;
ts.loadFlag = false;
if(ts.slideTimer) clearInterval(ts.slideTimer);
if(ts.set.auto) ts.slideTimer = setInterval(function(){$('#tsNext').trigger('click')}, ts.set.timer);
if(this.id == 'tsNext' ) {
(ts.count < ts.array.length-1) ? ts.count++ : ts.count = 0;
} else {
(ts.count > 0) ? ts.count-- : ts.count = ts.array.length-1;
};
clickSlide();
$('#tsCurrentImg').get(0).onload = function() {
clearInterval(ts.timer);
$('#tsLoading').css('display','none');
slideGetWH(this);
slideEffectIn(this);
};
});
return false;
});
function elemCreate(that) {
//var src = (ts.iebrows) ? that + "?" + new Date().getTime() : that;
var src = that + "?" + new Date().getTime();
var tag = '\
\
\
Loading...
\
\
\
';
$('body').prepend(tag);
ts.timer = setInterval( function(){ $('#tsLoading').fadeTo(700,0.3, function(){ $('#tsLoading').css('opacity',1)})} ,750);
(!ts.group) ? $('#tsTitle').text(that.title) : $('#tsImgBody').prepend('<< PREV
NEXT >>
');
if(ts.ibrows) $('#tsOverlay').css('height', document.body.scrollHeight + 'px');
};
function getOffset() {
if(ts.iebrows) {
ts.winInW = document.documentElement.clientWidth;
ts.winInH = document.documentElement.clientHeight;
ts.winX = document.documentElement.scrollLeft;
ts.winY = document.documentElement.scrollTop;
} else {
ts.winInW = window.innerWidth;
ts.winInH = window.innerHeight;
ts.winX = window.pageXOffset;
ts.winY = window.pageYOffset;
};
ts.l_posi_f = ts.winX + (ts.winInW - 300)/2;
ts.t_posi_f = ts.winY + (ts.winInH - 300)/2;
$('#tsImgBody').css('left',ts.l_posi_f + 'px').css('top',ts.t_posi_f + 'px');
};
function getWH(that) {
ts.imgElemWidth = $(that).width() + ts.set.borderW;
ts.imgElemHeight = $(that).height() + ts.set.borderW;
$('#tsCurrentImg').css('padding', ts.set.borderW/2 + 'px');
ts.l_posi = ts.winX + (ts.winInW - ts.imgElemWidth)/2;
ts.t_posi = ts.winY + (ts.winInH - ts.imgElemHeight)/2;
$('#tsUnderBar').css('width',ts.imgElemWidth + 'px').css('height', ts.set.underH + 'px');
};
function effectIn(z) {
var w = ts.imgElemWidth + 'px';
var h = ts.imgElemHeight + 'px';
var s = ts.set.speed;
switch(ts.set.type) {
case 1:
if(ts.imgElemWidth > ts.winInW && ts.imgElemHeight > ts.winInH) {
$('#tsImgBody').animate({left: ts.winX + 'px'}, s).animate({top: ts.winY + 'px'}, s).animate({width: w}, s).animate({height: h}, s, function() { imgIn(z) });
} else if(ts.imgElemWidth > ts.winInW) {
$('#tsImgBody').animate({left: ts.winX + 'px'}, s).animate({top: ts.t_posi + 'px'}, s).animate({width: w}, s).animate({height: h}, s, function() { imgIn(z) });
} else if(ts.imgElemHeight > ts.winInH) {
$('#tsImgBody').animate({left: ts.l_posi + 'px'}, s).animate({top: ts.winY + 'px'}, s).animate({width: w}, s).animate({height: h}, s, function() { imgIn(z) });
} else {
$('#tsImgBody').animate({left: ts.l_posi + 'px'}, s).animate({top: ts.t_posi + 'px'}, s).animate({width: w}, s).animate({height: h}, s, function() { imgIn(z) });
};
break;
case 2:
if(ts.imgElemWidth > ts.winInW && ts.imgElemHeight > ts.winInH) {
$('#tsImgBody').animate({left: ts.winX + 'px', top: ts.winY + 'px', width: w, height: h}, s, function() { imgIn(z) });
} else if(ts.imgElemWidth > ts.winInW) {
$('#tsImgBody').animate({left: ts.winX + 'px', top: ts.t_posi + 'px', width: w, height: h}, s, function() { imgIn(z) });
} else if(ts.imgElemHeight > ts.winInH) {
$('#tsImgBody').animate({left: ts.l_posi + 'px', top: ts.winY + 'px', width: w, height: h}, s, function() { imgIn(z) });
} else {
$('#tsImgBody').animate({left: ts.l_posi + 'px' ,top: ts.t_posi + 'px', width: w, height: h}, s, function() { imgIn(z) });
};
break;
case 3:
if(ts.imgElemWidth > ts.winInW && ts.imgElemHeight > ts.winInH) {
$('#tsImgBody').css({left: ts.winX + 'px', top: ts.winY + 'px', width: w, height: h}), imgIn(z);
} else if(ts.imgElemWidth > ts.winInW) {
$('#tsImgBody').css({left: ts.winX + 'px', top: ts.t_posi + 'px', width: w, height: h}), imgIn(z);
} else if(ts.imgElemHeight > ts.winInH) {
$('#tsImgBody').css({left: ts.l_posi + 'px', top: ts.winY + 'px', width: w, height: h}), imgIn(z);
} else {
$('#tsImgBody').css({left: ts.l_posi + 'px' ,top: ts.t_posi + 'px', width: w, height: h}), imgIn(z);
};
break;
};
};
function imgIn(z) {
var tar = (ts.group) ? '#tsUnderBar,#tsPrev,#tsNext' : '#tsUnderBar';
$('#tsCurrentImg').fadeIn(ts.set.speed, function() {
ts.loadFlag = true;
if(z) {
$(tar).animate({opacity: 0.5});
return;
}
if(ts.ibrows) {
$('#tsImgBody').toggle(
function() {$(tar).slideDown().css('opacity','0.5');
},
function() {$(tar).slideUp();
});
} else {
$('#tsImgBody').hover(
function(){$(tar).slideDown().css('opacity','0.5');
},
function() {$(tar).slideUp();
});
};
});
};
function outEvent() {
$('#tsOverlay,#tsClose').click(function() {
if(ts.slideTimer) clearInterval(ts.slideTimer);
if(ts.timer) clearInterval(ts.timer);
$('#tsOverlay,#tsImgBody,#tsCurrentImg').fadeOut('normal',function() {
$('#tsOverlay,#tsImgBody,#tsCurrentImg').remove();
});
});
};
function groupCreate(that) {
var strLen = that.rel.length
var str = that.rel.substring(3, strLen - 1);
var strLen_sub = new Array();
var str_sub = new Array();
ts.array = new Array();
var n = 0;
for(var j = 0, len = ts.elem.length; j < len; j++) {
strLen_sub[j] = ts.elem[j].rel.length;
str_sub[j] = ts.elem[j].rel.substring(3, strLen - 1);
if(str == str_sub[j]) {
ts.array.push([ts.elem[j],ts.elem[j].title]);
(ts.array[n][0] == that) ? ts.count = n : n++;
};
};
};
function clickSlide() {
$('#tsUnderBar,#tsNext,#tsPrev').css('opacity','0');
ts.subimgElemWidth = $('#tsCurrentImg').width();
ts.subimgElemHeight = $('#tsCurrentImg').height();
(ts.iebrows) ? ts.winY = document.documentElement.scrollTop : ts.winY = window.pageYOffset;
$('#tsCurrentImg').fadeOut('slow', function() {
$('#tsLoading').fadeIn('slow',function() {
if(!$('#tsCurrentImg').get(0)) return;
//$('#tsCurrentImg').get(0).src = (ts.iebrows) ? ts.array[ts.count][0] + "?" + new Date().getTime() : ts.array[ts.count][0];
$('#tsCurrentImg').get(0).src = ts.array[ts.count][0] + "?" + new Date().getTime();
});
});
ts.timer = setInterval( function(){ $('#tsLoading').fadeTo(700,0.3, function(){ $('#tsLoading').css('opacity',1)})} ,750);
$('#tsTitle').get(0).innerHTML = ts.array[ts.count][1] + '
' + (ts.count + 1) + '/' + ts.array.length;
};
function slideGetWH(that) {
ts.imgElemWidth = $(that).width() + ts.set.borderW;
ts.imgElemHeight = $(that).height() + ts.set.borderW;
$('#tsCurrentImg').css('padding', ts.set.borderW/2 + 'px');
};
function slideEffectIn(that) {
var z = true;
if(ts.subimgElemWidth !== $(that).width() || ts.subimgElemHeight !== $(that).height()) {
ts.l_posi = ts.winX + (ts.winInW - ts.imgElemWidth)/2;
ts.t_posi = ts.winY + (ts.winInH - ts.imgElemHeight)/2;
$('#tsUnderBar').css('width',ts.imgElemWidth + 'px').css('height', ts.set.underH + 'px');
effectIn(z);
} else {
imgIn(z);
};
};
}
});
})();