/* =========================================== */
/* js for arrinews */
/* $Id: mm_default.js 2485 2011-05-23 13:29:06Z ycody $ */
/* =========================================== */

$(document).ready(function(){
	
	/* ---------------- */
	/* cufon font stuff */
	/* ---------------- */
	//Cufon.replace('.titillium_wt600', {fontFamily:'titillium_wt600', hover: true, hoverables: { h1: true, h2: true }});
	//Cufon.replace('.titillium_wt800', {fontFamily:'titillium_wt800', hover: true, hoverables: { h1: true, h2: true }});
	Cufon.replace('.titillium_wt600', {fontFamily:'titillium_wt600'});
	Cufon.replace('.titillium_wt800', {fontFamily:'titillium_wt800'});
	
	/* --------------------- */
	/* main navigation hover */
	/* --------------------- */
	$('.js_rollover_hook').mouseenter(function(){
		$(this).fadeTo(400, 0.01);
	});
	$('.js_rollover_hook').mouseleave(function(){
		$(this).fadeTo(400, 1.0);
	});
	
	/* --------------------------------------------------------------------------- */
	/* main navigation language selection hover and drop down menu                 */
	/* functionality is dependant on the propper filename ("_rollover" is crucial) */
	/* --------------------------------------------------------------------------- */
	$('.langsel').each(function(){
		
		var initialSrcMainImage = $(this).children('img').attr('src');// image in main navigation
		var mainImageFileNameWithoutExtension = initialSrcMainImage.substring(0, initialSrcMainImage.lastIndexOf('.'));
		
		var initialSrcDropdownImage = $('.langsel_dropdown').contents().find('img').attr('src');// image in drop down
		var dropdownImageFileNameWithoutExtension = initialSrcDropdownImage.substring(0, initialSrcDropdownImage.lastIndexOf('.'));
			
		$(this).click(function(){
			$('.langsel_dropdown').slideDown('fast').show();
			$('.langsel_dropdown').hover(function(){// drop down hover
				$('.langsel_dropdown').contents().find('img').attr('src', dropdownImageFileNameWithoutExtension + '_rollover.' + /[^.]+$/.exec(initialSrcDropdownImage));
			}, function(){
				$('.langsel_dropdown').contents().find('img').attr('src', dropdownImageFileNameWithoutExtension + '.' + /[^.]+$/.exec(initialSrcDropdownImage));
			});
			$(this).hover(function(){
			}, function(){
				$('.langsel_dropdown').slideUp('slow');
			});
		});
		
		$(this).hover(function(){// main navigation hover
			$(this).children('img').attr('src', mainImageFileNameWithoutExtension + '_rollover.' + /[^.]+$/.exec(initialSrcMainImage));
		}, function(){
			$(this).children('img').attr('src', mainImageFileNameWithoutExtension + '.' + /[^.]+$/.exec(initialSrcMainImage));
		});
	});
	
	/* ---------------------------------------------- */
	/* main searchbox clear default value and set css */
	/* ---------------------------------------------- */
	$('.searchbox_input').focus(function(){
		var default_value = this.value;
		if(this.value == default_value){
			this.value = '';
			$(this).css('color', '#000');// don't use toggleClass here!
		}
	});
	$('.searchbox_input').blur(function(){
		var default_value = 'Search';
		if(this.value == ''){
			this.value = default_value;
			$(this).css('color', '#606060');
		}
	});
	
	/* ----------------------------------------------------------------- */
	/* news searchboxes clear default values, set css, ajax autocomplete */
	/* ----------------------------------------------------------------- */
	if($('#news_searchbox_wrapper').length){
		/* search for stories about */
		$('#form_fulltext_news_input').focus(function(){
			var default_value = this.value;
			if(this.value == default_value){
				this.value = '';
				$(this).css('color', '#000');
			}
		});
		$('#form_fulltext_news_input').blur(function(){
			if(this.value == ''){
				this.value = $('#form_fulltext_news_submit').attr('value');
				$(this).css('color', '#606060');
			}
		});
	}
	
	/* ------------------------------------------------------------------- */
	/* videos searchboxes clear default values, set css, ajax autocomplete */
	/* ------------------------------------------------------------------- */
	if($('#videos_searchbox_wrapper').length){
		/* search for videos about */
		$('#form_fulltext_videos_input').focus(function(){
			var default_value = this.value;
			if(this.value == default_value){
				this.value = '';
				$(this).css('color', '#000');
			}
		});
		$('#form_fulltext_videos_input').blur(function(){
			if(this.value == ''){
				this.value = $('#form_fulltext_videos_submit').attr('value');;
				$(this).css('color', '#606060');
			}
		});
	}
	
	/* -------------------------------- */
	/* paging (news, video)             */
	/* -------------------------------- */
	if($('#paging_wrapper').length || $('#video_paging_wrapper').length){
		$('.paging_box:not(.paging_box_current)').each(function(){
			$(this).hover(function(){
				$(this).addClass('paging_box_current');
			}, function(){
				$(this).removeClass('paging_box_current');
			});
		});
	}
	
	/* -------------------------------- */
	/* featured content bar boxes hover */
	/* -------------------------------- */
	$('.boxcontainer').mouseenter(function(){
		$(this).contents().find('p').not('.titillium_wt600').find('a').css('color', '#000');
		$(this).contents().find('p').not('.titillium_wt600').css('color', '#000');
		$(this).find('.boxcontent').not('.noarrowbg').toggleClass('boxcontent_hover');
		if (!(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 5)) {
			$(this).find('.video_overlay_icon').fadeTo(1, 0.9);
		}
		$(this).find('.hover_overlay_icon').fadeTo(1, 0.6);// image only, no text in the box (e.g. merchandise)
		$(this).prev('h1').css('color', '#000');
		if($('.boxbody_qotw').length){// quote of the week only in home
			$(this).contents().find('p').css('color', '#000');
			$(this).contents().find('p.titillium_wt600').find('a').css('color', '#2088d8');
			Cufon.refresh();
		}else{
			Cufon.refresh('.titillium_wt800');
		}
	});
	$('.boxcontainer').mouseleave(function(){
		$(this).contents().find('p').not('.titillium_wt600').find('a').css('color', '#606060');
		$(this).contents().find('p').not('.titillium_wt600').css('color', '#606060');
		$(this).find('.boxcontent').not('.noarrowbg').toggleClass('boxcontent_hover');
		if (!(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 5)) {
			$(this).find('.video_overlay_icon').fadeTo(1, 0.7);
		}
		$(this).find('.hover_overlay_icon').fadeTo(1, 0.0);// image only, no text in the box (e.g. merchandise)
		$(this).prev('h1').css('color', '#404040');
		if($('.boxbody_qotw').length){// quote of the week only in home
			$(this).contents().find('p').css('color', '#606060');
			$(this).contents().find('p.titillium_wt600').find('a').css('color', '#fff');
			Cufon.refresh();
		}else{
			Cufon.refresh('.titillium_wt800');
		}
	});
	
	/* ------------------------ */
	/* main content boxes hover */
	/* ------------------------ */
	if($('.boxcontainer_main').length){
		$('.boxcontainer_main').each(function(){
			$(this).hover(function(){
				$(this).contents().find('p').find('a').css('color', '#000');
				$('.bg_arrows', this).toggleClass('bg_arrows_hover');
				$('.boxcontent_main  h2.titillium_wt600 > a', this).toggleClass('hover_contentbox');
				if (!(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 5)) {
					$(this).find('.video_overlay_icon').fadeTo(1, 0.9);
				}
				$('.boxcontent_main h1.titillium_wt800', this).css('color', '#000');
				if($('.small_picturebox_headline').length){
					$(this).find('.small_picturebox_headline').css('color', '#000');
				}
				Cufon.refresh();
			}, function(){
				$(this).contents().find('p').find('a').css('color', '#606060');
				$('.bg_arrows', this).toggleClass('bg_arrows_hover');
				$('.boxcontent_main  h2.titillium_wt600 > a', this).toggleClass('hover_contentbox');
				if (!(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 5)) {
					$(this).find('.video_overlay_icon').fadeTo(1, 0.7);
				}
				$('.boxcontent_main h1.titillium_wt800', this).css('color', '#404040');
				if($('.small_picturebox_headline').length){
					$(this).find('.small_picturebox_headline').css('color', '#404040');
				}
				Cufon.refresh();
			});
		});
	}
	
	if($('.youtube_preview_maincontent').length){
		$('.youtube_preview_maincontent').hover(function(){
			$(this).contents().find('p').css('color', '#000');
		}, function(){
			$(this).contents().find('p').css('color', '#606060');
		});
	}
	
	/* --------------------------- */
	/* main content top link hover */
	/* --------------------------- */
	if($('.top_link').length){
		$('.top_link').hover(function(){
			$(this).addClass('top_link_hover');
		}, function(){
			$(this).removeClass('top_link_hover');
		});
	}
	
	/* --------------- */
	/* picture gallery */
	/* --------------- */
	if($('.picturegallery_smallpics_wrapper').length){
		$('.picturegallery_smallpic_box').each(function(){
			$(this).click(function(){
				var srcBigImage = $('.picturegallery_boxcontent').children('img').attr('src');// big image
				var srcSmallImage = $(this).contents().find('img').attr('src');
				if(srcSmallImage){
					$('.picturegallery_boxcontent').children('img').fadeTo('slow', 0.0, function() {
						$('.picturegallery_boxcontent').children('img').attr('src', srcSmallImage);
						$('.picturegallery_boxcontent').children('img').fadeTo('slow', 1.0);
					});
				}
				/*$(this).contents().find('img').fadeTo('slow', 0.0, function() {
					$(this).attr('src', srcBigImage);
					$(this).fadeTo('slow', 1.0);
				});*/
			});
		});
	}
	
	/* ---------------------------- */
	/* main content leadstory hover */
	/* ---------------------------- */
	if($('.leadstory').length){
		$('.leadstory').each(function(){
			$(this).hover(function(){
				$('.read_more_button').toggleClass('read_more_button_hover');
				$('h1.leadstory a').toggleClass('hover_leadstory');
				Cufon.refresh('.titillium_wt600');
			}, function(){
				$('.read_more_button').toggleClass('read_more_button_hover');
				$('h1.leadstory a').toggleClass('hover_leadstory');
				Cufon.refresh('.titillium_wt600');
			});
		});
	}
	
	/* ---------------------------------- */
	/* newsteaser hover (home, list view) */
	/* ---------------------------------- */
	if($('.newsteaser_container_2').length){
		$('.newsteaser_container_2').each(function(){
			$(this).hover(function(){
				$('.newsteaser_content > h2.titillium_wt600 > a', this).toggleClass('hover_news');
				Cufon.refresh('.titillium_wt600');
			}, function(){
				$('.newsteaser_content > h2.titillium_wt600 > a', this).toggleClass('hover_news');
				Cufon.refresh('.titillium_wt600');
			});
		});
	}
	
	/* ----------------------------------- */
	/* quotebox (noborder) list view hover */
	/* ----------------------------------- */
	if($('.quotebox_noborder_container').length){
		$('.quotebox_noborder_container').each(function(){
			$(this).hover(function(){
				$('.quotebox_noborder_body > h2.titillium_wt600 > a', this).toggleClass('hover_quotes');
				$('.quotebox_noborder_footer > a', this).toggleClass('hover_quotes');
				Cufon.refresh('.titillium_wt600');
			}, function(){
				$('.quotebox_noborder_body > h2.titillium_wt600 > a', this).toggleClass('hover_quotes');
				$('.quotebox_noborder_footer > a', this).toggleClass('hover_quotes');
				Cufon.refresh('.titillium_wt600');
			});
		});
	}
	
	/* -------------------------------------- */
	/* home -> highlights box -> arrows hover */
	/* -------------------------------------- */
	if($('.highlights_hook').length){
		$('.highlights_hook').each(function(){
		
			var initialSrcLeftImage = $('img.left').attr('src');
			var leftImageFileNameWithoutExtension = initialSrcLeftImage.substring(0, initialSrcLeftImage.lastIndexOf('.'));
			
			var initialSrcRightImage = $('img.right').attr('src');
			var rightImageFileNameWithoutExtension = initialSrcRightImage.substring(0, initialSrcRightImage.lastIndexOf('.'));
			
			$('img.left').hover(function(){
				$(this).attr('src', leftImageFileNameWithoutExtension + '_hover.' + /[^.]+$/.exec(initialSrcLeftImage));
			}, function(){
				$(this).attr('src', leftImageFileNameWithoutExtension + '.' + /[^.]+$/.exec(initialSrcLeftImage));
			});
			
			$('img.right').hover(function(){
				$(this).attr('src', rightImageFileNameWithoutExtension + '_hover.' + /[^.]+$/.exec(initialSrcRightImage));
			}, function(){
				$(this).attr('src', rightImageFileNameWithoutExtension + '.' + /[^.]+$/.exec(initialSrcRightImage));
			});
		});
	}
	
	
	/* --------------------- */
	/* video list view hover */
	/* --------------------- */
	if($('.videoboxcontainer').length){
		$("a[rel^='prettyPhoto']").prettyPhoto();
		$('.videoboxcontainer').each(function(){
			$(this).hover(function(){
				if (!(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 5)) {
					$(this).find('.videolist_overlay_icon').fadeTo(1, 0.9);
				}
				$('p', this).css('color', '#2088d8');
				Cufon.refresh('.titillium_wt600');
			}, function(){
				if (!(jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 5)) {
					$(this).find('.videolist_overlay_icon').fadeTo(1, 0.7);
				}
				$('p', this).css('color', '#0060ac');
				Cufon.refresh('.titillium_wt600');
			});
			if($(this).attr('id') != ''){
				if(isNaN($(this).attr('id'))){//youtube
					$.getScript( 'http://gdata.youtube.com/feeds/api/videos/' + encodeURIComponent( $(this).attr('id') ) + '?v=2&alt=json-in-script&callback=youtubeFeedCallbackListView' );
				}else{//vimeo
					$.getJSON('http://www.vimeo.com/api/v2/video/' + encodeURIComponent( $(this).attr('id') ) + '.json?callback=?', {format: "json"}, vimeoFeedCallbackListView);
				}
			}
		});
	}
	
	if($('.youtube_preview').length || $('.youtube_preview_maincontent').length){
		$("a[rel^='prettyPhoto']").prettyPhoto();
	}
	
	/* ------------------------------------------ */
	/* get at least some png's transparent in ie6 */
	/* ------------------------------------------ */
	if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 5) {
		if($('.boxbody_qotw').length){
			$('.topborder_01_qotw').supersleight({'imgs': false});
			$('.topborder_02_qotw').supersleight({'imgs': false});
			$('.bottomborder_02_qotw').supersleight({'imgs': false});
			$('.bottomborder_01_qotw').supersleight({'imgs': false});
			$('.subtextbox_qotw').supersleight({'imgs': false});
		}
		if($('.quotebox_small_noborder').length){
			$('.quotebox_small_noborder_head').supersleight({'imgs': false});
			$('.quotebox_small_noborder_footer').supersleight({'imgs': false});
		}
	}
	
});// End: (document).ready

/* ------------------------------------------------------ */
/* fix png ie6 transparency                               */
/* allinthehead.com/retro/338/supersleight-jquery-plugin  */
/* 24ways.org/2007/supersleight-transparent-png-in-ie6    */
/* cave: take care of performance and click issues        */
/* ------------------------------------------------------ */
if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 5) {
	jQuery.fn.supersleight = function(settings) {
		settings = jQuery.extend({
			imgs: true,
			backgrounds: true,
			shim: '/fileadmin/templates/images/pixel.gif',
			apply_positioning: true
		}, settings);
		
		return this.each(function(){
			jQuery(this).find('*').andSelf().each(function(i,obj) {
				var self = jQuery(obj);
				// background pngs
				if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
					var bg = self.css('background-image');
					var src = bg.substring(5,bg.length-2);
					var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
					var styles = {
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
						'background-image': 'url('+settings.shim+')'
					};
					self.css(styles);
				};
				// image elements
				if (settings.imgs && self.is('img[src$=png]')){
					var styles = {
						'width': self.width() + 'px',
						'height': self.height() + 'px',
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='crop')"
					};
					self.css(styles).attr('src', settings.shim);
				};
				// apply position to 'active' elements
				if (settings.apply_positioning && self.is('a, input') && (self.css('position') === '' || self.css('position') == 'static')){
					self.css('position', 'relative');
				};
			});
		});
	};
}

/* ------------------------------------------------------------- */
/* callback function for ajaxed youtube video data in news story */
/* ------------------------------------------------------------- */
function youtubeFeedCallbackMain( data ) {
	
	var youtube_markup = ' \
		<div class="topborder"></div> \
		<div class="boxbody_main"> \
			<div class="boxcontent_main bg_arrows"> \
				<span class="video_overlay_icon" onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');"><!-- --></span> \
				<span class="youtubeThumbnail"><img src="{thumbnailUrl}" alt="{videoTitle}" width="270" height="203" onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');" /></span> \
				<p onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');">{videoTitle}</p> \
			</div> \
		</div> \
		<div class="bottomborder"></div>';
	
	var thumbnails = data.entry[ "media$group" ][ "media$thumbnail" ];
	var thumbnailUrl = data.entry[ "media$group" ][ "media$thumbnail" ][1].url;
	var videoPlayerUrl = data.entry[ "media$group" ][ "media$player" ].url;
	
	var videoTitle = $('.youtube_preview_maincontent span.title').html();
	var videoTitleEscaped = escape(videoTitle);
	videoTitle = xmlencode(videoTitle);
	var videoDescription = escape($('.youtube_preview_maincontent span.description').html());
	
	toInject = youtube_markup.replace(/{videoTitle}/g,videoTitle).replace(/{videoDescription}/g,videoDescription).replace(/{thumbnailUrl}/g,thumbnailUrl).replace(/{videoPlayerUrl}/g,videoPlayerUrl).replace(/{videoTitleEscaped}/g,videoTitleEscaped);
	
	$('.youtube_preview_maincontent').html(toInject);
	
	if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 5) {
		$('.video_overlay_icon').supersleight({'imgs': false});
	}
	
	piwikTracker.setDocumentTitle('Magic Makers Videos: ' + videoTitle);
	piwikTracker.trackPageView();
}

/* ------------------------------------------------------ */
/* callback function for ajaxed youtube video data in FCB */
/* ------------------------------------------------------ */
function youtubeFeedCallback( data ) {
	
	var youtube_markup = ' \
		<div class="topborder"></div> \
		<div class="boxbody"> \
			<div class="boxcontent"> \
				<span class="video_overlay_icon" onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');"><!-- --></span> \
				<span class="youtubeThumbnail"><img src="{thumbnailUrl}" alt="{videoTitle}" width="270" height="203" onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');" /></span> \
				<p onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');">{videoTitle}</p> \
			</div> \
		</div> \
		<div class="bottomborder"></div>';
	
	//var videoTitle = xmlencode(data.entry[ "title" ].$t);
	//var videoDescription = xmlencode(data.entry[ "media$group" ][ "media$description" ].$t.replace( /\n/g, '<br/>' ));
	var thumbnails = data.entry[ "media$group" ][ "media$thumbnail" ];
	var thumbnailUrl = data.entry[ "media$group" ][ "media$thumbnail" ][1].url;
	var videoPlayerUrl = data.entry[ "media$group" ][ "media$player" ].url;
	
	var videoTitle = $('.youtube_preview span.title').html();
	var videoTitleEscaped = escape(videoTitle);
	videoTitle = xmlencode(videoTitle);
	var videoDescription = escape($('.youtube_preview span.description').html());
	
	toInject = youtube_markup.replace(/{videoTitle}/g,videoTitle).replace(/{videoDescription}/g,videoDescription).replace(/{thumbnailUrl}/g,thumbnailUrl).replace(/{videoPlayerUrl}/g,videoPlayerUrl).replace(/{videoTitleEscaped}/g,videoTitleEscaped);
	
	$('.youtube_preview').html(toInject);
	
	if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 5) {
		$('.video_overlay_icon').supersleight({'imgs': false});
	}
	
	piwikTracker.setDocumentTitle('Magic Makers Videos: ' + videoTitle);
	piwikTracker.trackPageView();
}


/* ------------------------------------------------------------------ */
/* callback function for ajaxed youtube video data in video list view */
/* ------------------------------------------------------------------ */
function youtubeFeedCallbackListView( data ) {
	
	var youtube_markup = ' \
		<div class="videobox_topborder"></div> \
		<div class="videoboxbody"> \
			<div class="videoboxcontent"> \
				<span class="videolist_overlay_icon" onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');"><!-- --></span> \
				<span class="youtubeThumbnailListView"><img src="{thumbnailUrl}" alt="{videoTitle}" width="300" height="225" onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');" /></span> \
			</div> \
		</div> \
		<div class="videobox_bottomborder"></div> \
		<p class="titillium_wt600" onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');"></p>';
	
	var videoID = data.entry[ "media$group" ][ "yt$videoid" ].$t;
	var thumbnails = data.entry[ "media$group" ][ "media$thumbnail" ];
	var thumbnailUrl = data.entry[ "media$group" ][ "media$thumbnail" ][1].url;
	var videoPlayerUrl = data.entry[ "media$group" ][ "media$player" ].url;
	
	var videoTitle = $('#' + videoID).find('span.title').html();
	var videoTitleEscaped = escape(videoTitle);
	videoTitle = xmlencode(videoTitle);
	var videoDescription = escape($('#' + videoID).find('span.description').html());
	
	toInject = youtube_markup.replace(/{videoTitle}/g,videoTitle).replace(/{videoDescription}/g,videoDescription).replace(/{thumbnailUrl}/g,thumbnailUrl).replace(/{videoPlayerUrl}/g,videoPlayerUrl).replace(/{videoID}/g,videoID).replace(/{videoTitleEscaped}/g,videoTitleEscaped);
	
	$('#' + videoID).html(toInject);
	Cufon.refresh('.titillium_wt600');
	
	if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 5) {
		$('.videolist_overlay_icon').supersleight({'imgs': false});
	}
	
	//piwikTracker.setDocumentTitle('Magic Makers Videos: ' + videoTitle);
	//piwikTracker.trackPageView();
}

/* ------------------------------------------------------------- */
/* callback function for ajaxed vimeo video data in news story */
/* ------------------------------------------------------------- */
function vimeoFeedCallbackMain( data ) {
	
	var youtube_markup = ' \
		<div class="topborder"></div> \
		<div class="boxbody_main"> \
			<div class="boxcontent_main bg_arrows"> \
				<span class="video_overlay_icon" onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');"><!-- --></span> \
				<span class="youtubeThumbnail"><img src="{thumbnailUrl}" alt="{videoTitle}" width="270" height="203" onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');" /></span> \
				<p onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');">{videoTitle}</p> \
			</div> \
		</div> \
		<div class="bottomborder"></div>';
	
	var videoID = data[0].id;
	var thumbnailUrl = data[0].thumbnail_large;
	var videoPlayerUrl = 'http://player.vimeo.com/video/?v=' + videoID;
	
	var videoTitle = $('.youtube_preview_maincontent span.title').html();
	var videoTitleEscaped = escape(videoTitle);
	videoTitle = xmlencode(videoTitle);
	var videoDescription = escape($('.youtube_preview_maincontent span.description').html());
	
	toInject = youtube_markup.replace(/{videoTitle}/g,videoTitle).replace(/{videoDescription}/g,videoDescription).replace(/{thumbnailUrl}/g,thumbnailUrl).replace(/{videoPlayerUrl}/g,videoPlayerUrl).replace(/{videoTitleEscaped}/g,videoTitleEscaped);
	
	$('.youtube_preview_maincontent').html(toInject);
	
	if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 5) {
		$('.video_overlay_icon').supersleight({'imgs': false});
	}
	
	piwikTracker.setDocumentTitle('Magic Makers Videos: ' + videoTitle);
	piwikTracker.trackPageView();
}

/* ------------------------------------------------------ */
/* callback function for ajaxed vimeo video data in FCB */
/* ------------------------------------------------------ */
function vimeoFeedCallback( data ) {
	
	var youtube_markup = ' \
		<div class="topborder"></div> \
		<div class="boxbody"> \
			<div class="boxcontent"> \
				<span class="video_overlay_icon" onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');"><!-- --></span> \
				<span class="youtubeThumbnail"><img src="{thumbnailUrl}" alt="{videoTitle}" width="270" height="203" onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');" /></span> \
				<p onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');">{videoTitle}</p> \
			</div> \
		</div> \
		<div class="bottomborder"></div>';
	
	var videoID = data[0].id;
	var thumbnailUrl = data[0].thumbnail_large;
	var videoPlayerUrl = 'http://player.vimeo.com/video/?v=' + videoID;
	
	var videoTitle = $('.youtube_preview span.title').html();
	var videoTitleEscaped = escape(videoTitle);
	videoTitle = xmlencode(videoTitle);
	var videoDescription = escape($('.youtube_preview span.description').html());
	
	toInject = youtube_markup.replace(/{videoTitle}/g,videoTitle).replace(/{videoDescription}/g,videoDescription).replace(/{thumbnailUrl}/g,thumbnailUrl).replace(/{videoPlayerUrl}/g,videoPlayerUrl).replace(/{videoTitleEscaped}/g,videoTitleEscaped);
	
	$('.youtube_preview').html(toInject);
	
	if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 5) {
		$('.video_overlay_icon').supersleight({'imgs': false});
	}
	
	piwikTracker.setDocumentTitle('Magic Makers Videos: ' + videoTitle);
	piwikTracker.trackPageView();
}

/* ------------------------------------------------------------------ */
/* callback function for ajaxed vimeo video data in video list view */
/* ------------------------------------------------------------------ */
function vimeoFeedCallbackListView( data ) {
	
	var youtube_markup = ' \
		<div class="videobox_topborder"></div> \
		<div class="videoboxbody"> \
			<div class="videoboxcontent"> \
				<span class="videolist_overlay_icon" onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');"><!-- --></span> \
				<span class="youtubeThumbnailListView"><img src="{thumbnailUrl}" alt="{videoTitle}" width="300" height="225" onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');" /></span> \
			</div> \
		</div> \
		<div class="videobox_bottomborder"></div> \
		<p class="titillium_wt600" onclick="$.prettyPhoto.open(\'{videoPlayerUrl}&amp;width=900&amp;height=530\',\'{videoTitleEscaped}\',\'{videoDescription}\');"></p>';
	
	var videoID = data[0].id;
	var thumbnailUrl = data[0].thumbnail_large;
	var videoPlayerUrl = 'http://player.vimeo.com/video/?v=' + videoID;
	
	var videoTitle = $('#' + videoID).find('span.title').html();
	var videoTitleEscaped = escape(videoTitle);
	videoTitle = xmlencode(videoTitle);
	var videoDescription = escape($('#' + videoID).find('span.description').html());
	
	toInject = youtube_markup.replace(/{videoTitle}/g,videoTitle).replace(/{videoDescription}/g,videoDescription).replace(/{thumbnailUrl}/g,thumbnailUrl).replace(/{videoPlayerUrl}/g,videoPlayerUrl).replace(/{videoID}/g,videoID).replace(/{videoTitleEscaped}/g,videoTitleEscaped);
	
	$('#' + videoID).html(toInject);
	Cufon.refresh('.titillium_wt600');
	
	if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 5) {
		$('.videolist_overlay_icon').supersleight({'imgs': false});
	}
	
	piwikTracker.setDocumentTitle('Magic Makers Videos: ' + videoTitle);
	piwikTracker.trackPageView();
}

/* ------------------------------------- */
/* encode quotes and other special chars */
/* in title and descr. from youtube data */
/* ------------------------------------- */
function xmlencode(string) {
    return string.replace(/\&/g,'&'+'amp;').replace(/</g,'&'+'lt;').replace(/>/g,'&'+'gt;').replace(/\'/g,'&'+'apos;').replace(/\"/g,'&'+'quot;');
}

/* ---------------------------------------- */
/* submit category search dropdown onchange */
/* ---------------------------------------- */
function categoryFormSubmit(){
	if($('#form_videosfilter_by_category').length){
		$('#form_videosfilter_by_category').submit();
	}
	if($('#form_newsfilter_by_category').length){
		$('#form_newsfilter_by_category').submit();
	}
}
