var ForzieriBar = { closed_state: 30, normal_state: 100, wishlist_state: 95, prive_state: 50, signup_state: 245, signin_state: 245, nologged_state: 80, actual_state: 'closed', actual_section: 'login_choice', selected_section: '', return_section: '', cookieOpenName: '', bar_animation: null, t_country: '', g_language: '', bar_content: null, bar_content_div: null, login_div: null, login_div_complete: null, login_choice: null, wishlist_button: null, prive_button: null, loader: null, menu: null, items_container: null, welcome: null, wishlist_div: null, prive_div: null, close_btn: null, wishlist_num_item: null, basket_action_div: null, toggle_button_up: '/forzieriBar/img/double_black_up.gif', toggle_button_down: '/forzieriBar/img/double_black_down.gif', logged: false, _animation1: null, _animation2: null, _animation3: null, _animation4: null, itemsObj: {}, itemsObj2: {}, itemsInWishlist: null, init: function() { if (!$('forzieriBar')) { return;}
this.bar_content = $('forzieriBar_content'); this.bar_content_div = $('fzb_content_div'); this.login_div = $('fzb_login_1'); this.login_div_complete = $('fzb_login_2'); this.login_choice = $('fzb_login_choice'); this.wishlist_button = $('fzb_wishlist_tab'); this.prive_button = $('fzb_prive_tab'); this.menu = $('fzb_primary_menu'); this.loader = $('fzb_loader'); this.items_container = $$('.items_container'); this.welcome = $('fzb_welcome'); this.wishlist_div = $('fzb_wishlist'); this.prive_div = $('fzb_prive'); this.close_btn = $$('#fzb_close a'); this.itemsInWishlistDiv = $('itemsInWishlist'); this.basket_action_div = $('fzb_basket_action'); this.bar_animation = new Fx.Morph(this.bar_content, {duration: 'short', transition: Fx.Transitions.Sine.easeOut}); this.setButtons(); this.resetItemsButtons(); this._setItemsInWishlist(); this.cookieOpenName = 'forzieriBarState'; var statusCookie = Cookie.read(this.cookieOpenName); if (statusCookie == null || statusCookie == 'closed') { this._setStatusCookie('closed');} else { switch(statusCookie) { case 'wishlist':
this.showWishlistAction(); break; case 'prive':
this.showPriveAction(); break;}
}
}, setButtons: function() { this.wishlist_button.addEvent('click', function() { ForzieriBar.showWishlistAction(); return false;}); if (this.prive_button) { this.prive_button.addEvent('click', function() { ForzieriBar.showPriveAction(); return false;});}
this.close_btn.addEvent('click', function() { ForzieriBar.toggleBox(); return false;});}, resetItemsButtons: function() { ForzieriBar._animation1 = null; ForzieriBar._animation2 = null; var elements = $$('.items_container .item'); var infoElements = $$('.items_container .item .info'); this.wishlist_num_item = $('num_item'); ForzieriBar._animation1 = new Fx.Elements(elements, {link: 'cancel', duration: 100, transition: Fx.Transitions.Sine.easeOut}); ForzieriBar._animation2 = new Fx.Elements(infoElements, {link: 'cancel', duration: 100, transition: Fx.Transitions.Sine.easeOut}); ForzieriBar._animation3 = new Fx.Morph(this.wishlist_num_item, {link: 'cancel', duration: 100, transition: Fx.Transitions.Sine.easeOut}); ForzieriBar.itemsObj = {}; ForzieriBar.itemsObj2 = {}; elements.forEach(function(t, i) { $('info_'+i).setStyles({ 'opacity': 0, 'display': 'block'
}); t.removeEvents('mouseover'); t.removeEvents('mouseout'); t.addEvent('mouseover', function() { ForzieriBar.moveWishItem(this);}); t.addEvent('mouseout', function() { ForzieriBar.hideWishItem(this);});});}, showWishlistAction: function() { if (!this.logged) { this.toggleLoginAction(); return;}
if (this.actual_state == 'closed') { this._setStatusCookie('wishlist');} else { this._setStatusCookie('closed');}
ForzieriBar.basket_action_div.setStyle('display', 'none'); if (this.actual_state == 'closed' || this.selected_section != 'wishlist')
{ this.return_section = 'welcome'; this.selected_section = 'wishlist'; height = this.wishlist_state; this._animateBar(height); this.actual_state = 'opened'; this.actual_section = this.selected_section; this.welcome.setStyle('display', 'none'); if (this.prive_button) { this.prive_div.setStyle('display', 'none');}
this.wishlist_div.setStyle('display', 'block'); this._setCloseBtn(false); this._selectButton(this.wishlist_button);}
else
{ this.selected_section = this.return_section; height = this.closed_state; this._animateBar(height); this.actual_state = 'closed'; this.actual_section = this.selected_section; this.return_section = ''; this.welcome.setStyle('display', 'block'); this.wishlist_div.setStyle('display', 'none'); this._setCloseBtn(true); this._selectButton(false);}
}, showPriveAction: function() { if (this.actual_state == 'closed') { this._setStatusCookie('prive');} else { this._setStatusCookie('closed');}
ForzieriBar.basket_action_div.setStyle('display', 'none'); if (this.actual_state == 'closed' || this.selected_section != 'prive')
{ this.return_section = 'welcome'; this.selected_section = 'prive'; height = this.prive_state; this._animateBar(height); this.actual_state = 'opened'; this.actual_section = this.selected_section; this.welcome.setStyle('display', 'none'); this.wishlist_div.setStyle('display', 'none'); this.prive_div.setStyle('display', 'block'); this._setCloseBtn(false); this._selectButton(this.prive_button);}
else
{ this.selected_section = this.return_section; height = this.closed_state; this._animateBar(height); this.actual_state = 'closed'; this.actual_section = this.selected_section; this.return_section = ''; this.welcome.setStyle('display', 'block'); this.prive_div.setStyle('display', 'none'); this._setCloseBtn(true); this._selectButton(false);}
}, toggleLoginAction: function() { this.selected_section = 'login_choice'; if (this.actual_state == 'closed') { this.actual_state = 'opened'
this._setCloseBtn(false); height = this.nologged_state;} else { this.actual_state = 'closed'; this._setCloseBtn(true); height = this.closed_state;}
this._animateBar(height); var elm1
var elm2; if (this.login_div.getStyle('opacity') > 0) { elm1 = this.login_div; elm2 = this.login_div_complete; elm2.setStyles({ 'opacity': 0, 'display': 'block'
});} else { elm1 = this.login_div_complete; elm2 = this.login_div;}
_animation1 = new Fx.Morph(elm1, {duration: 'short', transition: Fx.Transitions.Sine.easeOut}); _animation2 = new Fx.Morph(elm2, {duration: 'short', transition: Fx.Transitions.Sine.easeOut}); _animation1.start({ 'opacity': 0 }); _animation2.start({ 'opacity': 1 }); this.actual_section = 'login_choice';}, showLoginAction: function() { height = this.signin_state; this.selected_section = 'login'; this._animateBar(height); this.login_choice.setStyle('display', 'none'); this.menu.setStyle('display', 'none'); this.loader.setStyle('display', 'block'); var login_div = new Element('div', { 'id': 'fzb_login'
}); this.bar_content_div.adopt(login_div); this._loadContentAndPutIn('/forzieriBar/login.asp?l='+this.g_language+'&c='+this.t_country, login_div, false); this.return_section = this.actual_section; this.actual_section = 'login'; this.actual_state = 'opened'
}, showRegisterAction: function() { height = this.signup_state; this.selected_section = 'signup'; this._animateBar(height); this.login_choice.setStyle('display', 'none'); this.menu.setStyle('display', 'none'); this.loader.setStyle('display', 'block'); var signup_div = new Element('div', { 'id': 'fzb_signup'
}); this.bar_content_div.adopt(signup_div); this._loadContentAndPutIn('/forzieriBar/register.asp?l='+this.g_language+'&c='+this.t_country, signup_div, false); this.return_section = this.actual_section; this.actual_section = 'signup'; this.actual_state = 'opened'
}, toggleBox: function() { if (this.actual_state == 'opened') { if (this.actual_section == 'login_choice') { this.toggleLoginAction(); return;}
$('fzb_'+this.actual_section).setStyle('display', 'none'); if (this.return_section != '') { $('fzb_'+this.return_section).setStyle('display', 'block');}
this._setCloseBtn(true); this.actual_section = this.return_section; this.return_section = ''; this.selected_section = ''; height = this.closed_state; this._animateBar(height); this.actual_state = 'closed'; this.basket_action_div.setStyle('display', 'none'); this._selectButton(false); this._setStatusCookie('closed');}
else { this.showWishlistAction();}
}, moveWishItem: function(elm) { var id = $(elm).getProperty('id'); var num = id.replace('fzb_item_', '').toInt(); var elements = $$('.items_container .item'); elements.forEach(function(t, i) { if (i > num) { ForzieriBar.itemsObj[i] = {'left': 105};} else
{ ForzieriBar.itemsObj[i] = {'left': 0};}
if (i == num) { ForzieriBar.itemsObj2[i] = {'width': 80, 'opacity': 1};}
else
{ ForzieriBar.itemsObj2[i] = {'width': 0, 'opacity': 0};}
}); ForzieriBar._animation1.start(ForzieriBar.itemsObj); ForzieriBar._animation2.start(ForzieriBar.itemsObj2); ForzieriBar._animation3.start({ 'left': 100
}); var form = $(elm).getChildren(); form.forEach(function(t, i) { if ($(t).getProperty('class') == 'info') { var c = $(t).getChildren(); c.forEach(function(t, i) { if ($(t).getProperty('class') == 'addToBasketForm') { var a = $(t).getChildren(); a.forEach(function(t, i) { if (t.getProperty('class') == 'addToBasketBtn') { $(t).setStyle('display', 'block');}
});}
});}
});}, hideWishItem: function(elm) { var id = $(elm).getProperty('id'); var num = id.replace('fzb_item_', '').toInt(); var elements = $$('.items_container .item'); elements.forEach(function(t, i) { ForzieriBar.itemsObj[i] = {'left': 0}; ForzieriBar.itemsObj2[i] = {'width': 0, 'opacity': 0};}); ForzieriBar._animation1.start(ForzieriBar.itemsObj); ForzieriBar._animation2.start(ForzieriBar.itemsObj2); ForzieriBar._animation3.start({ 'left': 0
}); var form = $(elm).getChildren(); form.forEach(function(t, i) { if ($(t).getProperty('class') == 'info') { var c = $(t).getChildren(); c.forEach(function(t, i) { if ($(t).getProperty('class') == 'addToBasketForm') { var a = $(t).getChildren(); a.forEach(function(t, i) { if (t.getProperty('class') == 'addToBasketBtn') { $(t).setStyle('display', 'none');}
});}
});}
});}, changeWish: function(select, g_language, t_country) { var wishlist_id = $(select).options[$(select).selectedIndex].value; $('fzb_wishlist').setStyle('display', 'none'); this.loader.setStyle('display', 'block'); var request = new Request({ method: 'post', url: '/forzieriBar/getForzieriBarSession.asp?l='+g_language+'&c='+t_country, evalScripts: true
}); request.onSuccess = function(responseText) { $('fzb_wishlist').empty(); $('fzb_wishlist').set('html', responseText); ForzieriBar.loader.setStyle('display', 'none'); $('fzb_wishlist').setStyle('display', 'block'); ForzieriBar.resetItemsButtons(); ForzieriBar._setItemsInWishlist();}
request.onFailure = function(xhr) { alert('Failure Error! Try Again Later.');}
request.onException = function(headerName, value) { alert('Exception Error! Try Again Later.');}
request.send('wishlist_id='+wishlist_id);}, additemToWishlist: function(formName, url) { if (ForzieriBar.logged) { if (ForzieriBar.actual_state == 'closed' || this.selected_section != 'wishlist') { ForzieriBar.showWishlistAction();}
$('fzb_wishlist').setStyle('display', 'none'); ForzieriBar.loader.setStyle('display', 'block'); $(formName).set('send', { url: url, onComplete: function(responseText) { $('fzb_wishlist').empty(); $('fzb_wishlist').set('html', responseText); ForzieriBar.loader.setStyle('display', 'none'); $('fzb_wishlist').setStyle('display', 'block'); ForzieriBar.resetItemsButtons(); ForzieriBar._setItemsInWishlist();}
}); $(formName).send();}
else
{ if (ForzieriBar.actual_state == 'closed') { ForzieriBar.toggleLoginAction();}
}
}, additemToWishlistAjax: function(url) { if (ForzieriBar.logged) { var request = new Request({ url: url, evalScripts: true
}); if (ForzieriBar.actual_state == 'closed' || this.selected_section != 'wishlist') { ForzieriBar.showWishlistAction();}
$('fzb_wishlist').setStyle('display', 'none'); ForzieriBar.loader.setStyle('display', 'block'); request.onSuccess = function(responseText) { $('fzb_wishlist').empty(); $('fzb_wishlist').set('html', responseText); ForzieriBar.loader.setStyle('display', 'none'); $('fzb_wishlist').setStyle('display', 'block'); ForzieriBar.resetItemsButtons(); ForzieriBar._setItemsInWishlist();}
request.onFailure = function(xhr) { alert('Failure Error! Try Again Later.');}
request.onException = function(headerName, value) { alert('Exception Error! Try Again Later.');}
request.send('qty=1');}
else
{ if (ForzieriBar.actual_state == 'closed') { ForzieriBar.toggleLoginAction();}
}
}, addToBasket: function(id) { var form = $('addToBasketForm_'+id); var url = $(form).getProperty('action'); if (ForzieriBar.actual_state == 'closed' || this.selected_section != 'wishlist') { ForzieriBar.showWishlistAction();}
$('fzb_wishlist').setStyle('display', 'none'); ForzieriBar.loader.setStyle('display', 'block'); $(form).set('send', { url: url, onComplete: function(responseText) { if (responseText == 'ok') { ForzieriBar.basket_action_div.setStyle('display', 'block'); ForzieriBar.loader.setStyle('display', 'none'); addBasketItems();} else { alert('Error Occured!');}
}
}); $(form).send();}, returnToWishlist: function() { $('fzb_wishlist').setStyle('display', 'block'); ForzieriBar.loader.setStyle('display', 'none'); this.basket_action_div.setStyle('display', 'none');}, _animateBar: function(height) { this.bar_animation.start({ 'height': height
});}, _setStatusCookie: function(section) { Cookie.dispose(this.cookieOpenName); var statusCookie = Cookie.write(this.cookieOpenName, section, { duration: 1, path: '/' });}, _loadContentAndPutIn: function(url, element, evalScripts) { var request = new Request({ method: 'post', url: url, evalScripts: evalScripts
}); request.onSuccess = function(responseText) { ForzieriBar.loader.setStyle('display', 'none'); $(element).set('html', responseText.toString());}
request.onFailure = function(xhr) { ForzieriBar.loader.set('text', 'Failure Error! Try Again Later.');}
request.onException = function(headerName, value) { ForzieriBar.loader.set('text', 'Exception Error! Try Again Later.');}
request.send();}, _destroyAndClose: function() { var elm = 'fzb_'+this.actual_section; _animation1 = new Fx.Morph($(elm), {duration: 300, transition: Fx.Transitions.Sine.easeOut}); _animation1.start({ 'opacity': 0 }); _animation1.onComplete = function() { $(elm).destroy();}
this.toggleBox(); this._resetStates();}, _resetStates: function() { switch(this.actual_section) { case 'login_choice':
this.login_div.setStyles({ 'opacity': 1, 'display': 'block'
}); this.login_div_complete.setStyles({ 'opacity': 0, 'display': 'none'
}); this.login_choice.setStyle('display', 'block'); this.menu.setStyle('display', 'block'); break;}
}, _selectButton: function(btn) { this.wishlist_button.removeClass('selected'); if (this.prive_button) { this.prive_button.removeClass('selected');}
if (false != btn) { btn.addClass('selected');}
}, _setItemsInWishlist: function() { if (this.logged && (this.itemsInWishlist != null) && (this.itemsInWishlistDiv)) { this.itemsInWishlistDiv.set('text', this.itemsInWishlist);}
}, _setCloseBtn: function(close) { if (close) { this.close_btn.setStyle('background', "transparent url('"+this.toggle_button_up+"') center center no-repeat");} else { this.close_btn.setStyle('background', "transparent url('"+this.toggle_button_down+"') center center no-repeat");}
}
};