﻿// Getamped 1404 Official - Getamped 1404 - Premium vBulletin Services
// vBulletin Product : G.1404 : News and Announcements
// Copyright(c) 2011 Getamped 1404. All Rights Reserved.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// News and Announcements ticker function : Scroll
jQuery.fn.liScroll = function(settings)
{
	settings = jQuery.extend(
	{
		travelocity: 0.07
	}, settings);
	return this.each(function()
	{
		var $strip = jQuery(this);
		$strip.addClass("news_ticker")
		var stripWidth = 1;
		$strip.find("li").each(function(i)
		{
			stripWidth += jQuery(this, i).outerWidth(true);
		});
		var $mask = $strip.wrap("<div class='mask'></div>");
		var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");
		var containerWidth = $strip.parent().parent().width();
		$strip.width(stripWidth);
		var totalTravel = stripWidth+containerWidth;
		var defTiming = totalTravel/settings.travelocity;
		function scrollnews(spazio, tempo)
		{
			$strip.animate({left: '-='+ spazio}, tempo, "linear", function()
			{
				$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);
			});
		}
		scrollnews(totalTravel, defTiming);
		$strip.hover(function()
		{
			jQuery(this).stop();
		},
		function()
		{
			var offset = jQuery(this).offset();
			var residualSpace = offset.left + stripWidth;
			var residualTime = residualSpace/settings.travelocity;
			scrollnews(residualSpace, residualTime);
		});
	});	
};

// News and Announcements ticker fuction : SlideUp
(function($)
{
	if(!$.omr)
	{
		$.omr = new Object();
	};
	$.omr.totemticker = function(el, options )
	{
	  	var base = this;
	  	base.el = el;
	  	base.$el = $(el);
        base.$el.data("omr.totemticker", base);
	  	base.init = function()
		{
            base.options = $.extend({},$.omr.totemticker.defaultOptions, options);
           	base.ticker;
			base.format_ticker();
			base.setup_nav();
			base.start_interval();
        };
		base.start_interval = function()
		{
			clearInterval(base.ticker);
	    	base.ticker = setInterval(function()
			{
	    		base.$el.find('li:first').animate(
				{
	            	marginTop: '-' + base.options.row_height,
	            }, base.options.speed, function()
				{
	                $(this).detach().css('marginTop', '0').appendTo(base.$el);
	            });
	    	}, base.options.interval);
	    }
	    base.reset_interval = function()
		{
	    	clearInterval(base.ticker);
	    	base.start_interval();
	    }
	    base.stop_interval = function()
		{
	    	clearInterval(base.ticker);
	    }
		base.format_ticker = function()
		{
			if(typeof(base.options.max_items) != "undefined" && base.options.max_items != null)
			{
				var stripped_height = base.options.row_height.replace(/px/i, '');
				var ticker_height = stripped_height * base.options.max_items;
				base.$el.css({
					height		: ticker_height + 'px', 
					overflow	: 'hidden',	
				});
				
			}
			else
			{
				base.$el.css({
					overflow	: 'hidden',
				})
			}
		}
		base.setup_nav = function()
		{
			if (typeof(base.options.stop) != "undefined"  && base.options.stop != null)
			{
				$(base.options.stop).click(function(){
					base.stop_interval();
					return false;
				});
			}
			if (typeof(base.options.start) != "undefined"  && base.options.start != null)
			{
				$(base.options.start).click(function(){
					base.start_interval();
					return false;
				});
			}
			if (typeof(base.options.previous) != "undefined"  && base.options.previous != null)
			{
				$(base.options.previous).click(function()
				{
					base.$el.find('li:last').detach().prependTo(base.$el).css('marginTop', '-' + base.options.row_height);
					base.$el.find('li:first').animate({
				        marginTop: '0px',
				    }, base.options.speed, function ()
					{
				        base.reset_interval();
				    });
				    return false;
				});
			}
			if (typeof(base.options.next) != "undefined" && base.options.next != null)
			{
				$(base.options.next).click(function()
				{
					base.$el.find('li:first').animate({
						marginTop: '-' + base.options.row_height,
			        }, base.options.speed, function()
					{
			            $(this).detach().css('marginTop', '0px').appendTo(base.$el);
			            base.reset_interval();
			        });
			        return false;
				});
			}
			if (typeof(base.options.mousestop) != "undefined" && base.options.mousestop === true)
			{
				base.$el.mouseenter(function()
				{
					base.stop_interval();
				}).mouseleave(function()
				{
					base.start_interval();
				});
			}
		}
		base.debug_info = function()
		{
			console.log(base.options);
		}
		base.init();
	};
	$.omr.totemticker.defaultOptions = {
  		message		:	'Ticker Loaded',
  		next		:	null,
  		previous	:	null,
  		stop		:	null,
  		start		:	null,
		mousestop   :   true,
  		row_height	:	'30px',
  		speed		:	700,
  		interval	:	4000,
		max_items	: 	null,
	};
	$.fn.totemticker = function( options )
	{
		return this.each(function()
		{
			(new $.omr.totemticker(this, options));
		});
	};
})(jQuery);

// News and Announcements ticker function : Lined and Fade
(function($)
{
	$.fn.ticker = function(options)
	{
		var opts = $.extend({}, $.fn.ticker.defaults, options); 
		var newsID = '#' + $(this).attr('id');
		var tagType = $(this).get(0).tagName; 	
		return this.each(function()
		{
			var settings =
			{				
				position: 0,
				time: 0,
				distance: 0,
				newsArr: {},
				play: true,
				paused: false,
				contentLoaded: false,
				dom:{
					contentID: '#news-content',
					titleID: '#ticker-title',
					titleElem: '#ticker-title SPAN',
					tickerID : '#news',
					wrapperID: '#news-content-wrapper',
					revealID: '#news-swipe',
					revealElem: '#news-swipe SPAN',
					controlsID: '#ticker-controls',
					prevID: '#prev',
					nextID: '#next',
					playPauseID: '#play-pause'
				}
			};
			if (tagType != 'UL' && tagType != 'OL' && opts.htmlFeed === true)
			{
				debugError('Cannot use <' + tagType.toLowerCase() + '> type of element for this plugin - must of type <ul> or <ol>');
				return false;
			}
			opts.direction == 'rtl' ? opts.direction = 'right' : opts.direction = 'left';
			initialisePage();
			function countSize(obj)
			{
			    var size = 0, key;
			    for (key in obj)
				{
			        if (obj.hasOwnProperty(key)) size++;
			    }
			    return size;
			};
			function debugError(obj)
			{
				if (opts.debugMode)
				{
					if (window.console && window.console.log)
					{
						window.console.log(obj);
					}
					else
					{
						alert(obj);
					}
				}
			}
			function initialisePage()
			{
				$(settings.dom.wrapperID).append('<div id="' + settings.dom.tickerID.replace('#', '') + '"><div id="' + settings.dom.titleID.replace('#', '') + '"><span><!-- --></span></div><p id="' + settings.dom.contentID.replace('#', '') + '"></p><div id="' + settings.dom.revealID.replace('#', '') + '"><span><!-- --></span></div></div>');
				$(settings.dom.wrapperID).removeClass('no-js').addClass('has-js ' + opts.direction);
				$(settings.dom.tickerElem + ',' + settings.dom.contentID).hide();
				if (opts.controls)
				{
					$(settings.dom.controlsID).live('click mouseover mousedown mouseout mouseup', function (e)
					{
						var button = e.target.id;
						if (e.type == 'click')
						{	
							switch (button)
							{
								case settings.dom.prevID.replace('#', ''):
									settings.paused = true;
									$(settings.dom.playPauseID).addClass('paused');
									manualChangeContent(button);
									break;
								case settings.dom.nextID.replace('#', ''):
									settings.paused = true;
									$(settings.dom.playPauseID).addClass('paused');
									manualChangeContent(button);
									break;
								case settings.dom.playPauseID.replace('#', ''):
									if (settings.play == true)
									{
										settings.paused = true;
										$(settings.dom.playPauseID).addClass('paused');
										pauseTicker();
									}
									else
									{
										settings.paused = false;
										$(settings.dom.playPauseID).removeClass('paused');
										restartTicker();
									}
									break;
							}	
						}
						else if (e.type == 'mouseover' && $('#' + button).hasClass('controls'))
						{
							$('#' + button).addClass('over');
						}
						else if (e.type == 'mousedown' && $('#' + button).hasClass('controls'))
						{
							$('#' + button).addClass('down');
						}
						else if (e.type == 'mouseup' && $('#' + button).hasClass('controls'))
						{
							$('#' + button).removeClass('down');
						}
						else if (e.type == 'mouseout' && $('#' + button).hasClass('controls'))
						{
							$('#' + button).removeClass('over');
						}
					});
					$(settings.dom.wrapperID).append('<ul id="' + settings.dom.controlsID.replace('#', '') + '"><li id="' + settings.dom.playPauseID.replace('#', '') + '" class="controls"></li><li id="' + settings.dom.prevID.replace('#', '') + '" class="controls"></li><li id="' + settings.dom.nextID.replace('#', '') + '" class="controls"></li></ul>');
				}
				if (opts.displayType != 'fade')
				{
                	$(settings.dom.contentID).mouseover(function ()
					{
                		if (settings.paused == false)
						{
                			pauseTicker();
                		}
                	}).mouseout(function ()
					{
                		if (settings.paused == false)
						{
                			restartTicker();
                		}
                	});
				}
				processContent();
			}
			function processContent()
			{
				if (settings.contentLoaded == false)
				{
					if (opts.ajaxFeed)
					{
						if (opts.feedType == 'xml')
						{
							$.ajax({
								url: opts.feedUrl,
								cache: false,
								dataType: opts.feedType,
								async: true,
								success: function(data)
								{
									count = 0;	
									for (var a = 0; a < data.childNodes.length; a++)
									{
										if (data.childNodes[a].nodeName == 'rss')
										{
											xmlContent = data.childNodes[a];
										}
									}
									for (var i = 0; i < xmlContent.childNodes.length; i++)
									{
										if (xmlContent.childNodes[i].nodeName == 'channel')
										{
											xmlChannel = xmlContent.childNodes[i];
										}
									}
									for (var x = 0; x < xmlChannel.childNodes.length; x++)
									{
										if (xmlChannel.childNodes[x].nodeName == 'item')
										{
											xmlItems = xmlChannel.childNodes[x];
											var title, link = false;
											for (var y = 0; y < xmlItems.childNodes.length; y++)
											{
												if (xmlItems.childNodes[y].nodeName == 'title')
												{
													title = xmlItems.childNodes[y].lastChild.nodeValue;
												}
												else if (xmlItems.childNodes[y].nodeName == 'link')
												{
													link = xmlItems.childNodes[y].lastChild.nodeValue; 
												}
												if ((title !== false && title != '') && link !== false)
												{
												    settings.newsArr['item-' + count] = { type: opts.titleText, content: '<a href="' + link + '">' + title + '</a>' };
													count++;
													title = false;
													link = false;
												}
											}
										}
									}
									if (countSize(settings.newsArr < 1))
									{
										debugError('Couldn\'t find any content from the XML feed for the ticker to use!');
										return false;
									}
									setupContentAndTriggerDisplay();
									settings.contentLoaded = true;
								}
							});
						}
						else
						{
							debugError('Code Me!');	
						}
					}
					else if (opts.htmlFeed)
					{ 
						if($(newsID + ' LI').length > 0)
						{
							$(newsID + ' LI').each(function (i)
							{
								settings.newsArr['item-' + i] = { type: opts.titleText, content: $(this).html()};
							});
							setupContentAndTriggerDisplay();
						}
						else
						{
							debugError('Couldn\'t find HTML any content for the ticker to use!');
							return false;
						}
					}
					else
					{
						debugError('The ticker is set to not use any types of content! Check the settings for the ticker.');
						return false;
					}
				}
			}
			function setupContentAndTriggerDisplay()
			{
				settings.contentLoaded = true;
				$(settings.dom.titleElem).html(settings.newsArr['item-' + settings.position].type);
				$(settings.dom.contentID).html(settings.newsArr['item-' + settings.position].content);

				if (settings.position == (countSize(settings.newsArr) -1))
				{
					settings.position = 0;
				}
				else
				{		
					settings.position++;
				}

				distance = $(settings.dom.contentID).width();
				time = distance / opts.speed;
				revealContent();
			}
			function revealContent()
			{
				if(settings.play)
				{
					var offset = $(settings.dom.titleElem).width() + 20;
					$(settings.dom.revealID).css(opts.direction, offset + 'px');
					if (opts.displayType == 'fade')
					{
						$(settings.dom.revealID).hide(0, function ()
						{
							$(settings.dom.contentID).css(opts.direction, offset + 'px').fadeIn(opts.fadeInSpeed, postReveal);
						});						
					}
					else if (opts.displayType == 'scroll'){}
					else
					{
						$(settings.dom.revealElem).show(0, function ()
						{
							$(settings.dom.contentID).css(opts.direction, offset + 'px').show();
							animationAction = opts.direction == 'right' ? { marginRight: distance + 'px'} : { marginLeft: distance + 'px' };
							$(settings.dom.revealID).css('margin-' + opts.direction, '0px').delay(20).animate(animationAction, time, 'linear', postReveal);
						});		
					}
				}
				else
				{
					return false;
				}
			};
			function postReveal()
			{
				if(settings.play)
				{
					$(settings.dom.contentID).delay(opts.pauseOnItems).fadeOut(opts.fadeOutSpeed);
					if (opts.displayType == 'fade')
					{
						$(settings.dom.contentID).fadeOut(opts.fadeOutSpeed, function ()
						{
							$(settings.dom.wrapperID)
								.find(settings.dom.revealElem + ',' + settings.dom.contentID)
									.hide()
								.end().find(settings.dom.tickerID + ',' + settings.dom.revealID)
									.show()
								.end().find(settings.dom.tickerID + ',' + settings.dom.revealID)
									.removeAttr('style');
							setupContentAndTriggerDisplay();
						});
					}
					else
					{
						$(settings.dom.revealID).hide(0, function ()
						{
							$(settings.dom.contentID).fadeOut(opts.fadeOutSpeed, function ()
							{
								$(settings.dom.wrapperID)
									.find(settings.dom.revealElem + ',' + settings.dom.contentID)
										.hide()
									.end().find(settings.dom.tickerID + ',' + settings.dom.revealID)
										.show()
									.end().find(settings.dom.tickerID + ',' + settings.dom.revealID)
										.removeAttr('style');
								setupContentAndTriggerDisplay();
							});
						});
					}
				}
				else
				{
					$(settings.dom.revealElem).hide();
				}
			}
			function pauseTicker()
			{
				settings.play = false;
				$(settings.dom.tickerID + ',' + settings.dom.revealID + ',' + settings.dom.titleID + ',' + settings.dom.titleElem + ',' + settings.dom.revealElem + ',' + settings.dom.contentID).stop(true, true);
				$(settings.dom.revealID + ',' + settings.dom.revealElem).hide();
				$(settings.dom.wrapperID)
					.find(settings.dom.titleID + ',' + settings.dom.titleElem).show()
						.end().find(settings.dom.contentID).show();
			}
			function restartTicker()
			{
				settings.play = true;
				settings.paused = false;
				postReveal();
			}
			function manualChangeContent(direction)
			{
				pauseTicker();
				switch (direction)
				{
					case 'prev':
						if (settings.position == 0)
						{
							settings.position = countSize(settings.newsArr) -2;
						}
						else if (settings.position == 1)
						{
							settings.position = countSize(settings.newsArr) -1;
						}
						else
						{
							settings.position = settings.position - 2;
						}
						$(settings.dom.titleElem).html(settings.newsArr['item-' + settings.position].type);
						$(settings.dom.contentID).html(settings.newsArr['item-' + settings.position].content);
						break;
					case 'next':
						$(settings.dom.titleElem).html(settings.newsArr['item-' + settings.position].type);
						$(settings.dom.contentID).html(settings.newsArr['item-' + settings.position].content);
						break;
				}
				if (settings.position == (countSize(settings.newsArr) -1))
				{
					settings.position = 0;
				}
				else
				{
					settings.position++;
				}
			}
		});
	};
	$.fn.ticker.defaults ={
		speed: 0.10,
		ajaxFeed: false,
		feedUrl: '',
		feedType: 'xml',
		displayType: 'reveal',
		htmlFeed: true,
		debugMode: false,
		controls: false,
		titleText: '',
		direction: 'ltr',
		pauseOnItems: 3000,
		fadeInSpeed: 600,
		fadeOutSpeed: 300
	};
})(jQuery);

// News and Announcements Integrate feature : Notifications Popup
(function($)
{
	var IE6 = $.browser.msie && /MSIE 6.0/.test(navigator.userAgent), Timer, IE6FIX;
	$.notify_defaults = {
		margin: 10,
		position: 'bottom',
		width: 400,
		align: 'left',
		padding: 5,
		background: '#000',
		zIndex: 1000,
		color: '#fff',
		opacity: 0.8,
		cursor: 'help',
		msgCss: {
			fontSize: '11px',
			fontFamily: 'Verdana, tahoma',
			textAlign: 'justify'
		},
		effect: 'fade',
		speed: 1000,
		timeout: 0,
		clickClose: false,
		close: false,
		//{text: '[CLOSE]',css:{color: '#fff',fontSize: '10px',position: 'absolute',top: 5,right: 10,cursor: 'pointer'}},
		onShow: function(main){},
		onClose: function(){},
		classes: 'notify_class'
	}
	function close(obj)
	{
		var Obj = $(obj), onClose = Obj.data('onClose'), call = function()
		{
			remove(Obj);if($.isFunction(onClose)) onClose();
		},
		spd = Obj.data('speed');
		switch(Obj.data('effect'))
		{
			case 'none': Obj.hide('', call);
			case 'fade': Obj.fadeOut(spd, call);
			default: Obj.slideUp(spd, call);
		}
	}
	function remove(obj)
	{
		clearInterval(IE6FIX);
		clearTimeout(Timer);
		$(obj).find('div').unbind('click');
		$(obj).stop().remove();
	}
	function ie6TopFix()
	{
		var element = document.getElementById('notify_main');
		if(element)
		{
			element.style.top = parseInt(document.documentElement.scrollTop) + 'px';
		}
	}
	function ie6BottomFix()
	{
		var element = document.getElementById('notify_main');
		if(element)
		{
			element.style.top = parseInt(document.documentElement.scrollTop + document.documentElement.clientHeight - element.offsetHeight) + 'px';
		}
	}
	function show(msg, opt)
	{
		var Main = $('<div id="notify_main" class="notify_main"/>') .css({position: IE6 ? 'absolute' : 'fixed',overflow: 'hidden',zIndex: opt.zIndex,width: '100%',left: 0}).addClass(opt.classes).hide(),
			Spc = $('<div class="notify_spc"/>') .css('padding',opt.margin),
			Cont = $('<div class="notify_cont"/>') .css({position:'relative',cursor  : opt.cursor}),
			Bg = $('<div class="notify_bg"/>') .css({position: 'absolute',height: '100%',top: 0,left: 0,width: '100%',background: opt.background,zIndex: opt.zIndex + 1,opacity: opt.opacity}),
			Msg = $('<div class="notify_msg"/>') .css({position: 'relative',zIndex: opt.zIndex + 2,color: opt.color,padding: opt.padding}).css(opt.msgCss).html(msg);
			if(opt.position == 'bottom')
				Main.css('bottom',0)
			else
				Main.css('top',0);
			if(IE6)
			{
				Bg.css('height','1000px');
				if(opt.position == 'bottom')
				{
					Main.css('bottom','auto');
					IE6FIX = setInterval(function()
					{
						ie6BottomFix()
					},50);
				}
				else
				{
					IE6FIX = setInterval(function()
					{
						ie6TopFix()
					},50);
				}
			}
			if(opt.width != 'all')
			{
				Spc.css('width',parseInt(opt.width));
				if(opt.align == 'left')
					Spc.css('float','left')
				else if(opt.align == 'right')
					Spc.css('float','right')
				else
					Spc.css({marginLeft : 'auto',marginRight: 'auto'})
			}
			if(opt.close !== false)
			{
				Cont.append($('<div class="notify_close"/>').css(opt.close.css).css('zIndex', opt.zIndex + 4).html(opt.close.text).click(function(){close(Main)}))
			}
			$('body').append(Main.append(Spc.append(Cont.append(Bg).append(Msg))));
			var start = function()
			{
				if(opt.timeout > 0)	Timer = setTimeout(function(){close(Main);}, opt.timeout);
			}
			switch(opt.effect)
			{
				case 'none': Main.show('', start);
				case 'fade': Main.fadeIn(opt.speed, start);
				default: Main.slideDown(opt.speed, start);
			}
			if(opt.clickClose)
				Cont.click(function(){close(Main)});
			Main.data({effect : opt.effect,speed  : opt.speed,onClose: opt.onClose});
			if($.isFunction(opt.onShow))
				opt.onShow(Main);
	}
	$.notify = $.jN = function(msg, opt)
	{
		msg  = msg? msg : null;
		opt  = opt? opt : {};
		var opts = $.extend(true, {}, $.notify_defaults, opt);
		remove($('#notify_main'));show(msg, opts);
	}
	$.fn.notify = $.fn.jN = function(options)
	{
		return $.jN($(this).html(), options);
	}
	$.notify.close = function()
	{
		close($('#notify_main'));
	}
})(jQuery);
