(function($){ 		  
	$.fn.popupWindow = function(instanceSettings){
		
		return this.each(function(){
		
		$(this).click(function(){
		
		$.fn.popupWindow.defaultSettings = {
			centerBrowser:0, // center window over browser window? {1 (YES) or 0 (NO)}. overrides top and left
			centerScreen:0, // center window over entire screen? {1 (YES) or 0 (NO)}. overrides top and left
			height:625, // sets the height in pixels of the window.
			left:0, // left position when the window appears.
			location:0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
			menubar:0, // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
			resizable:0, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
			scrollbars:1, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
			status:0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
			width:1015, // sets the width in pixels of the window.
			windowName:null, // name of window set from the name attribute of the element that invokes the click
			windowURL:null, // url used for the popup
			top:0, // top position when the window appears.
			toolbar:0 // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
		};
		
		settings = $.extend({}, $.fn.popupWindow.defaultSettings, instanceSettings || {});
		
		var windowFeatures =    'height=' + settings.height +
								',width=' + settings.width +
								',toolbar=' + settings.toolbar +
								',scrollbars=' + settings.scrollbars +
								',status=' + settings.status + 
								',resizable=' + settings.resizable +
								',location=' + settings.location +
								',menuBar=' + settings.menubar;

				settings.windowName = this.name || settings.windowName;
				settings.windowURL = this.href || settings.windowURL;
				var centeredY,centeredX;
			
				if(settings.centerBrowser){						
					if ($.browser.msie) {//hacked together for IE browsers
						centeredY = (window.screenTop - 120) + ((((document.documentElement.clientHeight + 120)/2) - (settings.height/2)));
						centeredX = window.screenLeft + ((((document.body.offsetWidth + 20)/2) - (settings.width/2)));
					}else{
						centeredY = window.screenY + (((window.outerHeight/2) - (settings.height/2)));
						centeredX = window.screenX + (((window.outerWidth/2) - (settings.width/2)));
					}
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
				}else if(settings.centerScreen){
					centeredY = (screen.height - settings.height)/2;
					centeredX = (screen.width - settings.width)/2;
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + centeredX +',top=' + centeredY).focus();
				}else{
					window.open(settings.windowURL, settings.windowName, windowFeatures+',left=' + settings.left +',top=' + settings.top).focus();	
				}
				return false;
			});
			
		});	
	};
})(jQuery);


// JavaScript Document
$(document).ready(function() {

						   
						   
						   
						var wdth = window.screen.availWidth;
						var hght = window.screen.availHeight;
						
						$("a.iframe").fancybox({ 'hideOnContentClick': true,'frameWidth': 798,'frameHeight': 603,callbackOnClose: function() {$("#fancy_content").empty();}});	
						
						$("#mtvVideos a").fancybox({ 
							'hideOnContentClick': false,
							'frameWidth': 721,
							'frameHeight': 687,		
							'padding'				: false,
							'overlayOpacity'		: .7,
							'overlayShow'			: true,		
							'zoomSpeedIn'			: 600,
							'zoomSpeedOut'			: 500,
							'autoScale'				: false,
							callbackOnClose: function() {
								$("#fancy_content").empty();
								}
						});	
						
						$("#woodiesPledge #sweeps a#enterSweeps").popupWindow({ 
						centerBrowser:1,
						scrollbars:1,
						width:500,
						height:850 
						});
						
						$('#tsdBlog a').click(function(){
							parent.top.$('#fancy_close').trigger('click') 
							
						});						
						
						$('#pldg a').click(function(){
							$(this).popupWindow({ 
							centerBrowser:1 
							});
							//parent.top.$('#fancy_close').trigger('click')
						});

					$('#woodiesPledge #pledge a#takePledge').popupWindow({ 
						centerBrowser:1 
						});

					//	$('#pldg a').popupWindow({ 
					//	centerBrowser:1 
					//	}); 
											  
						   $("a.fancyBox").fancybox();
						  

// Accordion
$("#accordion").accordion({ header:'h4',autoHeight : false });
//Slide
//Find out how many  pages there are
if ($('body').attr('id') == 'videos') {
	var current = $('#videoPageContainer ul');
	$('#next').attr('href', '#'+current[1].id);
	$('#previous').attr('href', '#'+current[current.length - 1].id);
	for (i=0; i<current.length; i++){
		//build the top selector
		var page = i + 1;
		var activeNewSelector= '<div class=\"select\"><a class=\"active\" href=\"#' + current[i].id + '\" id=\"'+ page + '\">Page ' + page + '</a></div>';
		var newSelector = '<div class=\"select\"><a href=\"#' + current[i].id + '\" id=\"'+ page + '\">Page ' + page + '</a></div>';
		//show the first page, hide the rest
		if (i==0) {
		//set the indicator to class active
			$('#selectors').append(activeNewSelector);
			$(this).addClass('active');
		} else {
		//$(current[i]).css('display', 'hidden');
		$('#selectors').append(newSelector);
		};
	};
	$('#selectors div.select a').click( function(e) {
		e.preventDefault();
		//$('#selectors div.select a').removeClass('active');
		//$(this).addClass('active');
		var myHref = $(this).attr('href')
		
		jumpHref(myHref);
 	});

	$("#next").click( function(e) {
		e.preventDefault();
		var myHref = $(this).attr('href');
		jumpHref(myHref);
	});
	$("#previous").click( function(e) {
		e.preventDefault();
		var myHref = $(this).attr('href');
		jumpHref(myHref);
	});
	};
	}); 
function jumpHref(myHref) {
	myHref= myHref.split('#');
	myHref = '#'+myHref[1];
	
	var current = $('#videoPageContainer ul'); //get all uls in an array
	$('#videoPageContainer ul').fadeOut('slow').removeClass('active'); //fadeout the ul with class active, remove class
	$('#selectors div.select a').removeClass('active');//remove class active from all top selector dots
	//var selectors = $('#selectors div.select a');
	$('#selectors div.select a').each(function(){ //build array and search through selectors 
			//if(navigator.appName == "Microsoft Internet Explorer") { 
			var myHash = $(this).attr('href');
			myHash = myHash.split('#');
			var newHash = '#'+ myHash[1];
			if (newHash == myHref) {$(this).addClass('active');};
			//} else {
	//if ($(this).attr('href') == myHref) {$(this).addClass('active');};
	//	};//if the href matches the passed var add class active, else test alert
											   });
	$(myHref).fadeIn('slow').addClass('active'); //fade in the passed ID and set class to active
	
	for (i=0; i<current.length; i++){ //for loop to change the  next/previous buttons
					if (myHref == "#"+current[i].id) {
						var x = i-1;
						var y = i+1;
						
						if (x < 0) { x = current.length - 1};
						if (y >= current.length) { y = 0;};
						
						var nextHref = '#'+current[y].id;
						var prevHref = '#'+current[x].id;
						
						$('#next').attr('href', nextHref);
						$('#previous').attr('href', prevHref);
						};
				};
};


//Motionpoint switch language function
var MP = {
<!-- mp_trans_disable_start --> 
  Version: '1.0.22',
  Domains: {'es':'www.amfamlatino.com'},	
  SrcLang: 'en',
<!-- mp_trans_disable_end -->
  UrlLang: 'mp_js_current_lang',
  SrcUrl: unescape('mp_js_orgin_url'),
<!-- mp_trans_disable_start --> 	
  init: function(){
    if (MP.UrlLang.indexOf('p_js_')==1) {
      MP.SrcUrl=window.top.document.location.href;
      MP.UrlLang=MP.SrcLang;
  }
},
getCookie: function(name){
  var start=document.cookie.indexOf(name+'=');
  if(start < 0) return null;
  start=start+name.length+1;
  var end=document.cookie.indexOf(';', start);
  if(end < 0) end=document.cookie.length;
  while (document.cookie.charAt(start)==' '){ start++; }
  return unescape(document.cookie.substring(start,end));
},
setCookie: function(name,value,path,domain){
  var cookie=name+'='+escape(value);
  if(path)cookie+='; path='+path;
  if(domain)cookie+='; domain='+domain;
  var now=new Date();
  now.setTime(now.getTime()+1000*60*60*24*365);
  cookie+='; expires='+now.toUTCString();
  document.cookie=cookie;
},
switchLanguage: function(lang){
  if(lang!=MP.SrcLang){
    var script=document.createElement('SCRIPT');
    script.src=location.protocol+'//'+MP.Domains[lang]+'/'+MP.SrcLang+lang+'/?1023749632;'+encodeURIComponent(MP.SrcUrl);
	document.body.appendChild(script);
  } else if(lang==MP.SrcLang && MP.UrlLang!=MP.SrcLang){
    var script=document.createElement('SCRIPT');
    script.src=location.protocol+'//'+MP.Domains[MP.UrlLang]+'/'+MP.SrcLang+MP.UrlLang+'/?1023749634;'+encodeURIComponent(location.href);
	document.body.appendChild(script);
  }
  return false;
},
switchToLang: function(url) {
  window.top.location.href=url; 
}
<!-- mp_trans_disable_end -->   
};
