////////////////////////////////////////////////////////////////
// Bronto Email Signup
////////////////////////////////////////////////////////////////
//
// Rewritten[Bronto]
//

scSite.bronto = scSite.addComponent('bronto', function(comp)
{
	$.extend(comp, {
		init: function()
		{
			$('input.bronto_email_submit').click(comp.showSignup);
			comp.dialogElement = $('<div id="bronto_signup_form" />').hide().appendTo('body');
			
		},
		
		dialogElement: null,
		
		showSignup: function()
		{
			var email = $('.bronto_email_input').val();

			$('#bronto_signup_form')
				.hide()
				.attr('title', 'Email Signup')
				.html(
					$('<iframe id="bronto_signup_frame" />')
						.attr('src', '/holder_holderaction_bronto-signup-form.html?email='+ email)
						.attr('width', '100%')
						.attr('height', '560px')
						.attr('scrolling', 'no')
						.attr('frameborder', '0')
				)
				.dialog({
					width: 780,
					height: 600,
					modal: true
				});
			return false;
		}
	});
});


////////////////////////////////////////////////////////////////
// Window Popups
////////////////////////////////////////////////////////////////

//Frames breaker
var strHref = document.referrer;
if ( strHref.indexOf("snap.com") > -1 ){
	if (top.location != self.location) {
		top.location = self.location.href
	}
}


var MyChildWindow = null;

function popUp(URL, x, y, width, height) {
	window.name="MyParentWindow";
	var myName = "myNewWindow" + width;
	MyChildWindow = window.open(URL, myName, 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=1,width=' + width + ',height=' + height + ',left=' + x + ',top=' + y);
	MyChildWindow.focus();
//	return MyChildWindow;
}

function popUp2(URL) {
	popUp(URL, 10, 40, 515, 400);
}

function popUp3(URL) {
	popUp(URL, 10, 40, 400, 250);
}

function popUpAnon(URL, x, y, width, height) {
	var myName = "myNewWindow" + width;
	MyChildWindow = window.open(URL, myName, 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=1,width=' + width + ',height=' + height + ',left=' + x + ',top=' + y);
	MyChildWindow.focus();
	MyChildWindow;
//	return MyChildWindow;
}

function popUpAnon2(URL) {
	return popUpAnon(URL, 10, 40, 515, 400);
}

function popUpAnon3(URL) {
	return popUpAnon(URL, 10, 40, 400, 250);
}

function CloseAndRedirect(URL) {
	if (opener) {
		opener.location=URL;
		window.close();
	} else {
		this.location.href=URL;
	}
}

function CloseAndRefresh() {
	opener.location.reload(true);
	window.close();
}

function popUnder(URL, x, y, width, height) {
	window.name="MyParentWindow";
	myName = "myNewWindow" + width;
	MyChildWindow = window.open(URL, myName, 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=1,width=' + width + ',height=' + height + ',left=' + x + ',top=' + y);
	window.focus();
	return MyChildWindow();
}





////////////////////////////////////////////////////////////////
// Location
////////////////////////////////////////////////////////////////

function refreshPage() {
	window.location.reload();
}





////////////////////////////////////////////////////////////////
// Flash Video Player
////////////////////////////////////////////////////////////////


function toggleVideo() {
	scSite.itemVideo.playVideo();
}

// Flash video player runs this to update the status of pages.
function getUpdate(typ,pr1,pr2) {
	switch(typ)
	{
		case 'state':
			scSite.itemVideo.updateVideoState(pr1);
		break;
		case 'time':
			scSite.itemVideo.updateVideoTime(pr1, pr2);
		break;
	}
};

function stopVideo() {
	scSite.itemVideo.stopVideo();
}


////////////////////////////////////////////////////////////////
// Flash Video Player
////////////////////////////////////////////////////////////////

// Based on rb-youtube
scSite.youtubeVideo = scSite.addComponent('youtubeVideo', function(YTV)
{
	$.extend(YTV,
	{
		openPopupPlayer: function(ev)
		{
			ev.preventDefault();
			
			var $this = $(this);
			
			var popD = $this.data('sc-el-popup-dialog');
			//if( ! popD )
			//{
				var ytId =  $this.attr('href').replace("http://www.youtube.com/watch?v=", "");
			
				popD = $('<div style="text-align: center" />')
					.html("<object width='534' height='300'><param name='movie' value='http://www.youtube.com/v/" + ytId + "&hl=en&fs=0&rel=0&autoplay=1'></param><param name='allowFullScreen' value='false'></param><param name='allowscriptaccess' value='always'></param><embed src='http://www.youtube.com/v/" + ytId + "&hl=en&fs=0&rel=0&autoplay=1' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='false' width='534' height='300'></embed></object>")
					.appendTo('body')
					.hide()
					.dialog(
					{
						title: $this.attr('title'),
						width: 570,
						height: 350,
						close: function(eve,ui) {
							$this.data('sc-el-popup-dialog').remove(); // destroy from the DOM so that the audio doesn't keep playing in Internet Explorer
						}
					});
				$this.data('sc-el-popup-dialog', popD);
			/*
				// don't reopen since we are remove()ing on close now to make better for IE
			}
			//else
			//{
			//	alert('booger');
			//	popD.dialog('open');
			//}*/
		},
		
		init: function()
		{
			$('a.youtube-link').live('click', YTV.openPopupPlayer);
		}	
	});
});


/*

YAHOO.util.Event.onDOMReady(function()
{
	var links = YAHOO.util.Dom.getElementsByClassName('javascriptLink');
	if(links && links.length)
	{
		for( var i = 0; i < links.length; i++ )
		{
			var linkId = links[i].id;
			if(linkId.substr(-5) == '_trig')
			{
				linkId = linkId.substr(0, linkId.length - 5);
				var content = linkId.split('_')[2];

				var box = document.getElementById(linkId);
				if( box )
				{
					YAHOO.util.Event.addListener(linkId +'_trig', 'click', YAHOO.shopperschoice.loadContentSimpleData, content);
					YAHOO.util.Event.addListener(linkId +'_trig', 'click', YAHOO.shopperschoice.toggleContentBox, content);
					YAHOO.util.Event.addListener(linkId +'_tab', 'click', YAHOO.shopperschoice.toggleContentBox, content);
				}
			}
		}
	}
});

*/
