if (!sempre)
var sempre = {};
if (!listElementPush)
var listElementPush = [];
var chavePush = 0;
var arrayIndexException = [];
var isLoadPluginCarousel = false;
/*
* parameter obj
* title
* versal
* time
* srcImage
* link
* optBoxClose
*/
sempre.push = {
add: function (obj) {
listElementPush.push(obj);
},
list: function () {
return listElementPush;
},
getTime: function (chavePush) {
if (listElementPush.length > 0 && listElementPush.length >= chavePush)
return listElementPush[chavePush].time;
},
render: function (callback) {
var str = '';
var cssClass = "nine";
for (i = 0; i < listElementPush.length; i++) {
id = listElementPush[i].id;
if (polopoly.cookie.get("push-" + id) == null) {
str += '
';
str += ' ';
if (listElementPush[i].srcImage != '')
str += '
';
else
cssClass = "twelve teaser-sem-foto";
str += '
';
if (listElementPush[i].versal != '')
str += '
';
if (listElementPush[i].title != '')
str += '
';
str += '
';
str += '
';
if (listElementPush[i].optBoxClose == true) {
str += ' ';
str += '
';
str += '
';
str += '
';
str += '
';
str += '
';
}
str += '';
}
}
$("#efect-push").html(str);
if (listElementPush.length == 1)
sempre.push.initCarousel(callback);
callback();
},
validate: function (callback) {
for (i = 0; i < listElementPush.length; i++) {
id = listElementPush[i].id;
if (polopoly.cookie.get("push-" + id) == "true") {
arrayIndexException.push(i);
}
}
callback();
},
check: function (callback) {
if (arrayIndexException.length > 0) {
for (j = arrayIndexException.length - 1; j >= 0; j--) {
listElementPush.splice(arrayIndexException[j], 1);
}
}
callback();
},
init: function () {
if (listElementPush.length > 0) {
sempre.push.loadCarousel(function () {
sempre.push.validate(function () {
sempre.push.check(function () {
sempre.push.render(function () {
sempre.push.initCarousel(function () {
if(!listElementPush[chavePush].imageLeft)
$("#p-time").html(''+sempre.push.getTime(0)+'
');
else
$("#p-time").html(listElementPush[chavePush].imageLeft);
if (sempre.push.list().length > 0) {
$("#float-push").show();
}
if (isLoadPluginCarousel) {
sempre.push.loadCarouselPlugin(function () {
sempre.push.loadCarouselPluginConnected(function () {
});
});
}
});
});
});
});
});
}
},
initCarousel: function (callback) {
jQuery('#efect-push').jcarousel({
vertical: true,
scroll: 1,
auto: 20,
itemLoadCallback: sempre.push.setTimePush,
initCallback: sempre.push.carouselCallback
});
callback();
},
loadCarousel: function (callback) {
if (typeof jQuery('#efect-push').jcarousel == 'function') isLoadPluginCarousel = true;
var head = document.getElementsByTagName('body')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "/js/jquery.jcarousel.min.js";
script.onreadystatechange = callback;
script.onload = callback;
head.appendChild(script);
},
loadCarouselPlugin: function (callback) {
var head = document.getElementsByTagName('body')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "/js/plugins/jquery.jcarousel.min.js";
script.onreadystatechange = callback;
script.onload = callback;
head.appendChild(script);
},
loadCarouselPluginConnected: function (callback) {
var head = document.getElementsByTagName('body')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "/js/jcarousel.connected-carousels.js";
script.onreadystatechange = callback;
script.onload = callback;
head.appendChild(script);
},
setTimePush: function (carousel, state) {
if (state == 'next')
chavePush += 1;
if (state == 'prev' && chavePush > 0)
chavePush -= 1;
if(!listElementPush[chavePush].imageLeft)
$("#p-time").html(''+sempre.push.getTime(chavePush)+'
');
else
$("#p-time").html(listElementPush[chavePush].imageLeft);
sempre.push.setCookie(chavePush);
},
carouselCallback: function (carousel, state) {
carousel.reload();
},
setCookie: function (chavePush) {
if (listElementPush.length > 0) {
var id = listElementPush[chavePush].id;
if (polopoly.cookie.get("push-" + id) == null) {
polopoly.cookie.setForSession("push-" + id, "true");
}
}
}
};