﻿/* 100205.1723 */
var GNM = GNM||{};


/* XML Proxy */
GNM.proxy = '/global/interface/httprequest/hrproxy.asp?url=';


/* Timestamp */
GNM.timestamp = (new Date()).getTime();


/* CBS Live Streaming Window */
GNM.playcbslive = function() { cbsfeed = window.open('http://kotv.images.worldnow.com/images/incoming/livestreaming/09/CBSNews/cbspageKOTV.htm', 'cbsfeed', 'width=708, height=747, menubar=no, toolbar=no, location=no, status=no, resizable=no, scrollbars=no'); };


/* Sort API Feed By Priority */
GNM.sortFeedByPriority = function(feed, kind) {
	var items = [];
	var i = 0;
	while(items.length < $(feed).find(kind).length) {
		$(feed).find(kind + '[displayorder=' + i + ']').each(function(){items.push($(this));});
		i++;
	}
	return items;
};


/* Story Text Resize */
GNM.storyTextSize = function() {
	$('#WNStoryTextChangerOptionNormal').bind('click', function() { $('#WNStoryBody').css('font-size', '12px'); $('#WNStoryBody a').css('font-size', '12px'); });
	$('#WNStoryTextChangerOptionMedium').bind('click', function() { $('#WNStoryBody').css('font-size', '14px'); $('#WNStoryBody a').css('font-size', '14px'); });
	$('#WNStoryTextChangerOptionLarge').bind('click', function() { $('#WNStoryBody').css('font-size', '16px'); $('#WNStoryBody a').css('font-size', '16px'); });
	var t = setTimeout("$('#' + $('#WNStoryTextChanger').find('.wnTextChangerOption-on').attr('id')).click()", 1000);
};


/* Col2/3 Video Gallery + Tabs */
GNM.col23tabvg = {
	show:function(divId, opt) {
		var vgDiv = $('#' + divId);
		vgDiv.removeClass('noshow');
		vgDiv.addClass('gnmvg23');
		vgDiv.find('li:first').addClass('first');
		vgDiv.append('<div class="gallery"></div>');
		
		vgDiv.find('li').hover(
			function() { $(this).addClass('hover'); },
			function() { $(this).removeClass('hover'); }
		);
		
		vgDiv.find('ul a').click(function() {
			vgDiv.find('li').removeClass('selected');
			$(this).parent().addClass('selected');
			GNM.col23tabvg.showbiggallery(vgDiv.find('.gallery'), $(this).attr('rel'), 4);
			$(this).blur();
			return false;
		});
		
		if(opt.cbslive) {
			vgDiv.append('<div class="cbslive"></div>');
			GNM.vg.showcbslive(vgDiv.find('.cbslive'));
		}
		
		vgDiv.find('ul a:first').click();
	},
	
	showbiggallery:function(galDiv, videoCat, maxClips) {
		galDiv.addClass('loading');
		galDiv.empty();
		$.get(GNM.proxy + 'http://api.worldnow.com/feed/v2.0/categories/' + videoCat + '/clips', function(data) {
			galDiv.removeClass('loading');
			galDiv.html('<table cellspacing="10"><tr></tr></table>');
			var sortedClips = $(GNM.sortFeedByPriority($(data), 'clip'));
			var clipNb = (sortedClips.length > maxClips) ? maxClips : sortedClips.length;
			for(var i = 0; i < clipNb; i++) {
				var clip = $(sortedClips[i]);
				galDiv.find('tr').append('<td class="' + clip.find('id:first').text() + '"><div class="gnmvgthumb"><span></span><img src="' + clip.find('abstractimage:first filename').text() + '"></div>' + clip.find('headline:first').text() + '</td>');
			}
			galDiv.find('td').click(function() { window.location = '/Global/category.asp?C=121535&clipId=' + $(this).attr('class') + '&topVideoCatNo=' + videoCat + '&autoStart=true'; });
			galDiv.find('td').mouseover(function() { $(this).find('.gnmvgthumb span').addClass('play'); });
			galDiv.find('td').mouseout(function() { $(this).find('.gnmvgthumb span').removeClass('play'); });
		});
	}
};


/* Col4 Video Gallery */
GNM.col4vg = {
	show:function(divId, catId) {
		$.get(GNM.proxy + 'http://api.worldnow.com/feed/v2.0/categories/' + catId + '/clips/', function(data) {
			
			var sortedClips = $(GNM.sortFeedByPriority($(data), 'clip'));
			
			var clipsPerPageNb = 3;
			var maxClipsNb = 9;
			var clipsNb = (sortedClips.length > maxClipsNb) ? maxClipsNb : sortedClips.length;
			var pagesNb = Math.ceil(clipsNb / 3);
			
			var prevBt = "http://ftpcontent.worldnow.com/kotv/videogallery/col4/img/prev.png";
			var prevOnBt = "http://ftpcontent.worldnow.com/kotv/videogallery/col4/img/prev-on.png";
			var nextBt = "http://ftpcontent.worldnow.com/kotv/videogallery/col4/img/next.png";
			var nextOnBt = "http://ftpcontent.worldnow.com/kotv/videogallery/col4/img/next-on.png";
			var dotBt = "http://ftpcontent.worldnow.com/kotv/videogallery/col4/img/dot.png";
			var dotOnBt = "http://ftpcontent.worldnow.com/kotv/videogallery/col4/img/dot-on.png";
			
			var vgDiv = $('#' + divId);
			vgDiv.removeClass('noshow');
			vgDiv.addClass('gnmvg4');
			vgDiv.append('<div class="gallery"><table cellspacing="3"><tr></tr></table></div>');
			if(pagesNb > 1) {
				vgDiv.find('h3').wrapInner(document.createElement("span"));
				vgDiv.find('h3').append('<div class="pnav"></div>');
				vgDiv.find('h3 .pnav').append('<a class="prev" href="#"><img src="' + prevBt + '"></a>');
				for(var i = 0; i < pagesNb; i++) vgDiv.find('h3 .pnav').append('<a class="dot" rel="' + i + '" href="#"><img src="' + dotBt + '"></a>');
				vgDiv.find('h3 .pnav').append('<a class="next" href="#"><img src="' + nextBt + '"></a>');
				
				vgDiv.find('.pnav .prev').mouseover(function() { $(this).find('img').attr('src', prevOnBt); });
				vgDiv.find('.pnav .prev').mouseout(function() { $(this).find('img').attr('src', prevBt); });
				vgDiv.find('.pnav .next').mouseover(function() { $(this).find('img').attr('src', nextOnBt); });
				vgDiv.find('.pnav .next').mouseout(function() { $(this).find('img').attr('src', nextBt); });
				
				vgDiv.find('.pnav .dot').click(function() { showPage(parseFloat($(this).attr('rel'))); $(this).blur(); return false; });
				vgDiv.find('.pnav .prev').click(function() { if(pageIndex > 0) showPage(pageIndex - 1); $(this).blur(); return false; });
				vgDiv.find('.pnav .next').click(function() { if(pageIndex < pagesNb - 1) showPage(pageIndex + 1); $(this).blur(); return false; });
			}
			
			var pageIndex = 0;
			showPage(0);
			
			function showPage(p) {
				pageIndex = p;
				
				vgDiv.find('.pnav .dot img').attr('src', dotBt);
				vgDiv.find('.pnav .dot img').eq(p).attr('src', dotOnBt);
				
				vgDiv.find('tr').empty();
				for(var i = 0; i < clipsPerPageNb; i++) {
					var clipIndex = i + 3 * p;
					var clip = $(sortedClips[clipIndex]);
					vgDiv.find('tr').append('<td class="' + clip.find('id:first').text() + '"><div class="gnmvgthumb"><span></span><img src="' + clip.find('abstractimage:first filename').text() + '"></div>' + clip.find('headline:first').text() + '</td>')
				}
				vgDiv.find('td').click(function() { window.location = '/Global/category.asp?C=121535&clipId=' + $(this).attr('class') + '&topVideoCatNo=' + catId + '&autoStart=true' });
				vgDiv.find('td').mouseover(function() { $(this).find('.gnmvgthumb span').addClass('play'); });
				vgDiv.find('td').mouseout(function() { $(this).find('.gnmvgthumb span').removeClass('play'); });
			}
			
		});
	}
};


/* Col4 Video Gallery + Tabs */
GNM.col4tabvg = {
	show:function(divId, opt) {
		var vgDiv = $('#' + divId);
		vgDiv.removeClass('noshow');
		vgDiv.addClass('gnmvg4');
		vgDiv.find('li:first').addClass('first');
		vgDiv.append('<div class="gallery"></div>');
		
		vgDiv.find('li').hover(
			function() { $(this).addClass('hover'); },
			function() { $(this).removeClass('hover'); }
		);
		
		vgDiv.find('ul a').click(function() {
			vgDiv.find('li').removeClass('selected');
			$(this).parent().addClass('selected');
			GNM.col4tabvg.showsmallgallery(vgDiv.find('.gallery'), $(this).attr('rel'), 3);
			$(this).blur();
			return false;
		});
		
		vgDiv.find('ul a:first').click();
	},
	
	showsmallgallery:function(galDiv, videoCat, maxClips) {
		galDiv.addClass('loading');
		galDiv.empty();
		$.get(GNM.proxy + 'http://api.worldnow.com/feed/v2.0/categories/' + videoCat + '/clips', function(data) {
			galDiv.removeClass('loading');
			galDiv.html('<table cellspacing="3"><tr></tr></table>');
			var sortedClips = $(GNM.sortFeedByPriority($(data), 'clip'));
			var clipNb = (sortedClips.length > maxClips) ? maxClips : sortedClips.length;
			for(var i = 0; i < clipNb; i++) {
				var clip = $(sortedClips[i]);
				galDiv.find('tr').append('<td class="' + clip.find('id:first').text() + '"><div class="gnmvgthumb"><span></span><img src="' + clip.find('abstractimage:first filename').text() + '"></div>' + clip.find('headline:first').text() + '</td>');
			}
			galDiv.find('td').click(function() { window.location = '/Global/category.asp?C=121535&clipId=' + $(this).attr('class') + '&topVideoCatNo=' + videoCat + '&autoStart=true'; });
			galDiv.find('td').mouseover(function() { $(this).find('.gnmvgthumb span').addClass('play'); });
			galDiv.find('td').mouseout(function() { $(this).find('.gnmvgthumb span').removeClass('play'); });
		});
	}
};


/* Video Gallery - Common */
GNM.vg = {
	showcbslive:function(cbsDiv) {
		$.get(GNM.proxy + 'http%3A%2F%2Fcbsnewspath.blogspot.com%2Ffeeds%2Fposts%2Fdefault', function(data) {
			cbsDiv.append('<a href="javascript:GNM.playcbslive();">' + $(data).find('entry:first title:first').text() + '.<span> Watch Live Now &gt;</span></a>');
		});
	}
};


/* Story Beacon */
GNM.beacon = function() {
	if(wng_pageInfo.containerType == 'S') {
		var storyId = wng_pageInfo.containerId;
		var storyTitle = escape($('meta[name="WT.ti"]').attr('content'));
		var station = wng_pageInfo.affiliateName;
		var comments = 0;
		$(($.trim($('.topix_commentLink a').text())).split(' ')).each(function(){ if(!isNaN(parseFloat(this))) comments = this; });
		
		/* Story + Comment Count */
		$('body').append('<img src="http://www2.newson6.com/beacon/?id=' + storyId + '&s=' + station + '&c=' + comments + '&t=' + storyTitle + '" width="1" height="1" border="0">');
		
		/* Email Count */
		$('#WNStoryUtils .wnSUEmail a').click(function() {
			$('body').append('<img src="http://www2.newson6.com/beacon/email/?id=' + storyId + '&s=' + station + '" width="1" height="1" border="0">');
		});
	}
};

/* Story Zoom */
GNM.zoom = function() {
	if(wng_pageInfo.containerType == 'S') {
		$('.wnStoryBodyGraphic img').wrap('<a></a>');
		$('.wnStoryBodyGraphic a').each(function(){
			$(this).attr('href', $(this).find('img').attr('src'));
			$(this).attr('title', $(this).find('img').attr('title'));
		});
		$('.wnStoryBodyGraphic a').attr('rel', 'storygallery');
		$('.wnStoryBodyGraphic a').append('<p style="margin:3px 0;">Enlarge this picture</p>');
		$('.wnStoryBodyGraphic a').fancybox({
			'zoomOpacity':true,
			'zoomSpeedIn':300,
			'zoomSpeedOut':300
		});
		$('.wnStoryBodyGraphic a').click(function(){ pageTracker._trackPageview("/events/zoom"); });
	}
};

/* Custom Weather Alert Ticker */
GNM.wxalert = function() {
	var wxAlertDiv = $('#WNCols234-5 #WNDS40');
	if (wxAlertDiv.length == 1) {
		wxAlertDiv.empty().after('<div id="gnmwxalert" class="wnDS40 wnDSContainer-standard" style="visibility:visible; font-weight:bold; text-align:center; padding-top:4px;"><a href="/global/weatheralerts.asp">WEATHER ALERTS IN EFFECT: Click here for a complete list of WATCHES and WARNINGS.</a></div>');
	}
};

/* Custom Headers + Ads */
GNM.headerAds = {
	init:function() {
		switch(wng_pageInfo.contentClassification) {
			case 'Weather':
				if (wng_pageInfo.containerType == 'C') GNM.headerAds.show('http://kotv.images.worldnow.com/images/incoming/headers/2009/Ads/weather645KOTV.htm');
				break;
			case 'University - Technology':
				if (wng_pageInfo.containerType == 'S') GNM.headerAds.show('http://kotv.images.worldnow.com/images/incoming/headers/2009/Ads/weatherheadlines645KOTV.htm');
				break;
			case 'Food Recipe':
				if (wng_pageInfo.containerType == 'S') GNM.headerAds.show('http://kotv.images.worldnow.com/images/incoming/Headers/2009/Ads/recipes645KOTV.htm');
				break;
		}
	},
	show:function(frameUrl) {
		$('#WNCol23Top').prepend('<iframe src="' + frameUrl + '" width="645" height="50" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="margin-bottom:15px;"></iframe>');
	}
};

/* WN Search Bar Enhancement */
GNM.wnsb = function() {
	$('#WNContainerMemberSearch-cols2345top .wnQueryText').focus(function() { $(this).removeClass('showtip'); });
	$('#WNContainerMemberSearch-cols2345top .wnQueryText').blur(function() { if ($(this).val() == '') $(this).addClass('showtip'); });
	$('#WNContainerMemberSearch-cols2345top .wnQueryText').blur();
};

/* I Need This Search Bar */
GNM.intsb = function() {
	$('#WNHeader h1').html('<iframe scrolling="no" width="320" height="23" frameborder="0" style="float:right; margin-right:1px;" marginheight="0" marginwidth="0" src="http://www2.news9.com/ineedthis/_searchbar/news9.com/default.html" id="gnmhdr-ineedthis"></iframe>');
};

/* Site Tabs */
GNM.sitetabs = function() {
	$('#WNHeader h1').addClass('sitetabs');
	$('#WNHeader h1').append('<div id="gnmsitetabs"><a id="gnmsitetabs-n9" href="http://www.news9.com"></a><a id="gnmsitetabs-no6" class="active" href="http://www.newson6.com"></a><a id="gnmsitetabs-okblitz" href="http://www.okblitz.com"></a><a id="gnmsitetabs-918moms" href="http://www.918moms.com"></a><a id="gnmsitetabs-cw" href="http://www.cw12-19.com/"></a></div>');
};

/* iPhone Banner */
GNM.iphoneMsg = function() {
	if(wng_pageInfo.contentClassification == 'Homepage')
		if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))){
			$('#WNHeader h1').before('<div class="gnmIphoneMsg"><a href="http://m.newson6.com/"><span class="iplarge">Visit our new iPhone optimized site!</span><span class="ipsmall">Accessible now on m.newson6.com</span></a></div>');
		}
};


/* **** // **** // JQUERY PLUGINS // **** // **** */

/*
 * FancyBox - simple and fancy jQuery plugin
 * Examples and documentation at: http://fancy.klade.lv/
 * Version: 1.2.1 (13/03/2009)
 * Copyright (c) 2009 Janis Skarnelis
 * Licensed under the MIT License: http://en.wikipedia.org/wiki/MIT_License
 * Requires: jQuery v1.3+
*/
;(function($) {

	$.fn.fixPNG = function() {
		return this.each(function () {
			var image = $(this).css('backgroundImage');

			if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) {
				image = RegExp.$1;
				$(this).css({
					'backgroundImage': 'none',
					'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=" + ($(this).css('backgroundRepeat') == 'no-repeat' ? 'crop' : 'scale') + ", src='" + image + "')"
				}).each(function () {
					var position = $(this).css('position');
					if (position != 'absolute' && position != 'relative')
						$(this).css('position', 'relative');
				});
			}
		});
	};

	var elem, opts, busy = false, imagePreloader = new Image, loadingTimer, loadingFrame = 1, imageRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i;
	var isIE = ($.browser.msie && parseInt($.browser.version.substr(0,1)) < 8);

	$.fn.fancybox = function(settings) {
		settings = $.extend({}, $.fn.fancybox.defaults, settings);

		var matchedGroup = this;

		function _initialize() {
			elem = this;
			opts = settings;

			_start();

			return false;
		};

		function _start() {
			if (busy) return;

			if ($.isFunction(opts.callbackOnStart)) {
				opts.callbackOnStart();
			}

			opts.itemArray		= [];
			opts.itemCurrent	= 0;

			if (settings.itemArray.length > 0) {
				opts.itemArray = settings.itemArray;

			} else {
				var item = {};

				if (!elem.rel || elem.rel == '') {
					var item = {href: elem.href, title: elem.title};

					if ($(elem).children("img:first").length) {
						item.orig = $(elem).children("img:first");
					}

					opts.itemArray.push( item );

				} else {
					
					var subGroup = $(matchedGroup).filter("a[rel=" + elem.rel + "]");

					var item = {};

					for (var i = 0; i < subGroup.length; i++) {
						item = {href: subGroup[i].href, title: subGroup[i].title};

						if ($(subGroup[i]).children("img:first").length) {
							item.orig = $(subGroup[i]).children("img:first");
						}

						opts.itemArray.push( item );
					}

					while ( opts.itemArray[ opts.itemCurrent ].href != elem.href ) {
						opts.itemCurrent++;
					}
				}
			}

			if (opts.overlayShow) {
				if (isIE) {
					$('embed, object, select').css('visibility', 'hidden');
				}

				$("#fancy_overlay").css('opacity', opts.overlayOpacity).show();
			}

			_change_item();
		};

		function _change_item() {
			$("#fancy_right, #fancy_left, #fancy_close, #fancy_title").hide();

			var href = opts.itemArray[ opts.itemCurrent ].href;

			if (href.match(/#/)) {
				var target = window.location.href.split('#')[0]; target = href.replace(target, ''); target = target.substr(target.indexOf('#'));

				_set_content('<div id="fancy_div">' + $(target).html() + '</div>', opts.frameWidth, opts.frameHeight);

			} else if (href.match(imageRegExp)) {
				imagePreloader = new Image; imagePreloader.src = href;

				if (imagePreloader.complete) {
					_proceed_image();

				} else {
					$.fn.fancybox.showLoading();

					$(imagePreloader).unbind().bind('load', function() {
						$(".fancy_loading").hide();

						_proceed_image();
					});
				}

			 } else if (href.match("iframe") || elem.className.indexOf("iframe") >= 0) {
				_set_content('<iframe id="fancy_frame" onload="$.fn.fancybox.showIframe()" name="fancy_iframe' + Math.round(Math.random()*1000) + '" frameborder="0" hspace="0" src="' + href + '"></iframe>', opts.frameWidth, opts.frameHeight);

			} else {
				$.get(href, function(data) {
					_set_content( '<div id="fancy_ajax">' + data + '</div>', opts.frameWidth, opts.frameHeight );
				});
			}
		};

		function _proceed_image() {
			if (opts.imageScale) {
				var w = $.fn.fancybox.getViewport();

				var r = Math.min(Math.min(w[0] - 36, imagePreloader.width) / imagePreloader.width, Math.min(w[1] - 60, imagePreloader.height) / imagePreloader.height);

				var width = Math.round(r * imagePreloader.width);
				var height = Math.round(r * imagePreloader.height);

			} else {
				var width = imagePreloader.width;
				var height = imagePreloader.height;
			}

			_set_content('<img alt="" id="fancy_img" src="' + imagePreloader.src + '" />', width, height);
		};

		function _preload_neighbor_images() {
			if ((opts.itemArray.length -1) > opts.itemCurrent) {
				var href = opts.itemArray[opts.itemCurrent + 1].href;

				if (href.match(imageRegExp)) {
					objNext = new Image();
					objNext.src = href;
				}
			}

			if (opts.itemCurrent > 0) {
				var href = opts.itemArray[opts.itemCurrent -1].href;

				if (href.match(imageRegExp)) {
					objNext = new Image();
					objNext.src = href;
				}
			}
		};

		function _set_content(value, width, height) {
			busy = true;

			var pad = opts.padding;

			if (isIE) {
				$("#fancy_content")[0].style.removeExpression("height");
				$("#fancy_content")[0].style.removeExpression("width");
			}

			if (pad > 0) {
				width	+= pad * 2;
				height	+= pad * 2;

				$("#fancy_content").css({
					'top'		: pad + 'px',
					'right'		: pad + 'px',
					'bottom'	: pad + 'px',
					'left'		: pad + 'px',
					'width'		: 'auto',
					'height'	: 'auto'
				});

				if (isIE) {
					$("#fancy_content")[0].style.setExpression('height',	'(this.parentNode.clientHeight - 20)');
					$("#fancy_content")[0].style.setExpression('width',		'(this.parentNode.clientWidth - 20)');
				}

			} else {
				$("#fancy_content").css({
					'top'		: 0,
					'right'		: 0,
					'bottom'	: 0,
					'left'		: 0,
					'width'		: '100%',
					'height'	: '100%'
				});
			}

			if ($("#fancy_outer").is(":visible") && width == $("#fancy_outer").width() && height == $("#fancy_outer").height()) {
				$("#fancy_content").fadeOut("fast", function() {
					$("#fancy_content").empty().append($(value)).fadeIn("normal", function() {
						_finish();
					});
				});

				return;
			}

			var w = $.fn.fancybox.getViewport();

			var itemLeft	= (width + 36)	> w[0] ? w[2] : (w[2] + Math.round((w[0] - width - 36) / 2));
			var itemTop		= (height + 50)	> w[1] ? w[3] : (w[3] + Math.round((w[1] - height - 50) / 2));

			var itemOpts = {
				'left':		itemLeft,
				'top':		itemTop,
				'width':	width + 'px',
				'height':	height + 'px'
			};

			if ($("#fancy_outer").is(":visible")) {
				$("#fancy_content").fadeOut("normal", function() {
					$("#fancy_content").empty();
					$("#fancy_outer").animate(itemOpts, opts.zoomSpeedChange, opts.easingChange, function() {
						$("#fancy_content").append($(value)).fadeIn("normal", function() {
							_finish();
						});
					});
				});

			} else {

				if (opts.zoomSpeedIn > 0 && opts.itemArray[opts.itemCurrent].orig !== undefined) {
					$("#fancy_content").empty().append($(value));

					var orig_item	= opts.itemArray[opts.itemCurrent].orig;
					var orig_pos	= $.fn.fancybox.getPosition(orig_item);

					$("#fancy_outer").css({
						'left':		(orig_pos.left - 18) + 'px',
						'top':		(orig_pos.top  - 18) + 'px',
						'width':	$(orig_item).width(),
						'height':	$(orig_item).height()
					});

					if (opts.zoomOpacity) {
						itemOpts.opacity = 'show';
					}

					$("#fancy_outer").animate(itemOpts, opts.zoomSpeedIn, opts.easingIn, function() {
						_finish();
					});

				} else {

					$("#fancy_content").hide().empty().append($(value)).show();
					$("#fancy_outer").css(itemOpts).fadeIn("normal", function() {
						_finish();
					});
				}
			}
		};

		function _set_navigation() {
			if (opts.itemCurrent != 0) {
				$("#fancy_left, #fancy_left_ico").unbind().bind("click", function(e) {
					e.stopPropagation();

					opts.itemCurrent--;
					_change_item();

					return false;
				});

				$("#fancy_left").show();
			}

			if (opts.itemCurrent != ( opts.itemArray.length -1)) {
				$("#fancy_right, #fancy_right_ico").unbind().bind("click", function(e) {
					e.stopPropagation();

					opts.itemCurrent++;
					_change_item();

					return false;
				});

				$("#fancy_right").show();
			}
		};

		function _finish() {
			_set_navigation();

			_preload_neighbor_images();

			$(document).keydown(function(e) {
				if (e.keyCode == 27) {
					$.fn.fancybox.close();
					$(document).unbind("keydown");

				} else if(e.keyCode == 37 && opts.itemCurrent != 0) {
					opts.itemCurrent--;
					_change_item();
					$(document).unbind("keydown");

				} else if(e.keyCode == 39 && opts.itemCurrent != (opts.itemArray.length - 1)) {
 					opts.itemCurrent++;
					_change_item();
					$(document).unbind("keydown");
				}
			});

			if (opts.centerOnScroll) {
				$(window).bind("resize scroll", $.fn.fancybox.scrollBox);
			} else {
				$("div#fancy_outer").css("position", "absolute");
			}

			if (opts.hideOnContentClick) {
				$("#fancy_wrap").click($.fn.fancybox.close);
			}

			$("#fancy_overlay, #fancy_close").bind("click", $.fn.fancybox.close);

			$("#fancy_close").show();

			if (opts.itemArray[ opts.itemCurrent ].title !== undefined && opts.itemArray[ opts.itemCurrent ].title.length > 0) {
				$('#fancy_title div').html(opts.itemArray[ opts.itemCurrent ].title);
				$('#fancy_title').show();
			}

			if (opts.overlayShow && isIE) {
				$('embed, object, select', $('#fancy_content')).css('visibility', 'visible');
			}

			if ($.isFunction(opts.callbackOnShow)) {
				opts.callbackOnShow();
			}

			busy = false;
		};

		return this.unbind('click').click(_initialize);
	};

	$.fn.fancybox.scrollBox = function() {
		var pos = $.fn.fancybox.getViewport();

		$("#fancy_outer").css('left', (($("#fancy_outer").width()	+ 36) > pos[0] ? pos[2] : pos[2] + Math.round((pos[0] - $("#fancy_outer").width()	- 36)	/ 2)));
		$("#fancy_outer").css('top',  (($("#fancy_outer").height()	+ 50) > pos[1] ? pos[3] : pos[3] + Math.round((pos[1] - $("#fancy_outer").height()	- 50)	/ 2)));
	};

	$.fn.fancybox.getNumeric = function(el, prop) {
		return parseInt($.curCSS(el.jquery?el[0]:el,prop,true))||0;
	};

	$.fn.fancybox.getPosition = function(el) {
		var pos = el.offset();

		pos.top	+= $.fn.fancybox.getNumeric(el, 'paddingTop');
		pos.top	+= $.fn.fancybox.getNumeric(el, 'borderTopWidth');

		pos.left += $.fn.fancybox.getNumeric(el, 'paddingLeft');
		pos.left += $.fn.fancybox.getNumeric(el, 'borderLeftWidth');

		return pos;
	};

	$.fn.fancybox.showIframe = function() {
		$(".fancy_loading").hide();
		$("#fancy_frame").show();
	};

	$.fn.fancybox.getViewport = function() {
		return [$(window).width(), $(window).height(), $(document).scrollLeft(), $(document).scrollTop() ];
	};

	$.fn.fancybox.animateLoading = function() {
		if (!$("#fancy_loading").is(':visible')){
			clearInterval(loadingTimer);
			return;
		}

		$("#fancy_loading > div").css('top', (loadingFrame * -40) + 'px');

		loadingFrame = (loadingFrame + 1) % 12;
	};

	$.fn.fancybox.showLoading = function() {
		clearInterval(loadingTimer);

		var pos = $.fn.fancybox.getViewport();

		$("#fancy_loading").css({'left': ((pos[0] - 40) / 2 + pos[2]), 'top': ((pos[1] - 40) / 2 + pos[3])}).show();
		$("#fancy_loading").bind('click', $.fn.fancybox.close);

		loadingTimer = setInterval($.fn.fancybox.animateLoading, 66);
	};

	$.fn.fancybox.close = function() {
		busy = true;

		$(imagePreloader).unbind();

		$("#fancy_overlay, #fancy_close").unbind();

		if (opts.hideOnContentClick) {
			$("#fancy_wrap").unbind();
		}

		$("#fancy_close, .fancy_loading, #fancy_left, #fancy_right, #fancy_title").hide();

		if (opts.centerOnScroll) {
			$(window).unbind("resize scroll");
		}

		__cleanup = function() {
			$("#fancy_overlay, #fancy_outer").hide();

			if (opts.centerOnScroll) {
				$(window).unbind("resize scroll");
			}

			if (isIE) {
				$('embed, object, select').css('visibility', 'visible');
			}

			if ($.isFunction(opts.callbackOnClose)) {
				opts.callbackOnClose();
			}

			busy = false;
		};

		if ($("#fancy_outer").is(":visible") !== false) {
			if (opts.zoomSpeedOut > 0 && opts.itemArray[opts.itemCurrent].orig !== undefined) {
				var orig_item	= opts.itemArray[opts.itemCurrent].orig;
				var orig_pos	= $.fn.fancybox.getPosition(orig_item);

				var itemOpts = {
					'left':		(orig_pos.left - 18) + 'px',
					'top': 		(orig_pos.top  - 18) + 'px',
					'width':	$(orig_item).width(),
					'height':	$(orig_item).height()
				};

				if (opts.zoomOpacity) {
					itemOpts.opacity = 'hide';
				}

				$("#fancy_outer").stop(false, true).animate(itemOpts, opts.zoomSpeedOut, opts.easingOut, __cleanup);

			} else {
				$("#fancy_outer").stop(false, true).fadeOut("fast", __cleanup);
			}

		} else {
			__cleanup();
		}

		return false;
	};

	$.fn.fancybox.build = function() {
		var html = '';

		html += '<div id="fancy_overlay"></div>';

		html += '<div id="fancy_wrap">';

		html += '<div class="fancy_loading" id="fancy_loading"><div></div></div>';

		html += '<div id="fancy_outer">';

		html += '<div id="fancy_inner">';

		html += '<div id="fancy_close"></div>';

		html +=  '<div id="fancy_bg"><div class="fancy_bg fancy_bg_n"></div><div class="fancy_bg fancy_bg_ne"></div><div class="fancy_bg fancy_bg_e"></div><div class="fancy_bg fancy_bg_se"></div><div class="fancy_bg fancy_bg_s"></div><div class="fancy_bg fancy_bg_sw"></div><div class="fancy_bg fancy_bg_w"></div><div class="fancy_bg fancy_bg_nw"></div></div>';

		html +=  '<a href="javascript:;" id="fancy_left"><span class="fancy_ico" id="fancy_left_ico"></span></a><a href="javascript:;" id="fancy_right"><span class="fancy_ico" id="fancy_right_ico"></span></a>';

		html += '<div id="fancy_content"></div>';

		html +=  '<div id="fancy_title"></div>';

		html += '</div>';

		html += '</div>';

		html += '</div>';

		$(html).appendTo("body");

		$('<table cellspacing="0" cellpadding="0" border="0"><tr><td class="fancy_title" id="fancy_title_left"></td><td class="fancy_title" id="fancy_title_main"><div></div></td><td class="fancy_title" id="fancy_title_right"></td></tr></table>').appendTo('#fancy_title');

		if (isIE) {
			$("#fancy_inner").prepend('<iframe class="fancy_bigIframe" scrolling="no" frameborder="0"></iframe>');
			$("#fancy_close, .fancy_bg, .fancy_title, .fancy_ico").fixPNG();
		}
	};

	$.fn.fancybox.defaults = {
		padding				:	10,
		imageScale			:	true,
		zoomOpacity			:	false,
		zoomSpeedIn			:	0,
		zoomSpeedOut		:	0,
		zoomSpeedChange		:	300,
		easingIn			:	'swing',
		easingOut			:	'swing',
		easingChange		:	'swing',
		frameWidth			:	425,
		frameHeight			:	355,
		overlayShow			:	true,
		overlayOpacity		:	0.3,
		hideOnContentClick	:	true,
		centerOnScroll		:	true,
		itemArray			:	[],
		callbackOnStart		:	null,
		callbackOnShow		:	null,
		callbackOnClose		:	null
	};

	$(document).ready(function() {
		$.fn.fancybox.build();
	});

})(jQuery);
/*
 * /FancyBox
*/


/**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { /* name and value given, set cookie */
        options = options || {};
        if (value === null) {
            value = '';
            options = $.extend({}, options); /* clone object since it's unexpected behavior if the expired property were changed */
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); /* use expires attribute, max-age is not supported by IE */
        }
        /* NOTE Needed to parenthesize options.path and options.domain */
        /* in the following expressions, otherwise they evaluate to undefined */
        /* in the packed version for some reason... */
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { /* only name given, get cookie */
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                /* Does this cookie string begin with the name we want? */
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
/*
 * /JQuery Cookie
*/


/* Autostart */

$(document).ready(function()
{
	GNM.iphoneMsg();
	GNM.beacon();
	GNM.zoom();
	//GNM.wxalert();
	GNM.storyTextSize();
	GNM.headerAds.init();
	GNM.wnsb();
	GNM.intsb();
	GNM.sitetabs();
});

