/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var URLEncoder = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}
// --------------------------------------------------------------------------------------
// Non-jQuery function initializations
// --------------------------------------------------------------------------------------

/*
IE PNG fix
*/

// if MSIE, apply style rule - selector { behavior: url(iepngfix.htc) }
if ( document.all && /MSIE (5\.5|6)/.test(navigator.userAgent) &&
     document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule)
{
	document.styleSheets[0].addRule('*', 'behavior: url(/en/styles/iepngfix.htc)');
	// Feel free to add rules for specific elements only, as above.
	// You have to call this once for each selector, like so:
	//document.styleSheets[0].addRule('img', 'behavior: url(iepngfix.htc)');
	//document.styleSheets[0].addRule('div', 'behavior: url(iepngfix.htc)');
}

/*
Suppress IE errors
*/
/*
function silentErrorHandler() {return true;}
window.onerror=silentErrorHandler;
*/


// --------------------------------------------------------------------------------------
// jQuery script & funciton initializations
// --------------------------------------------------------------------------------------

$(document).ready(function() {

    /*
    Load hacks for IE
    */
    // This code writes a link to the appropriate stylesheet after determining which 
    // version of IE is viewing the page. The new stylesheet will be inserted after
    // the last link element on the page -- $('link:last').after('');
    // Alternately it can be inserted before the closing </head> tag -- $('head').append('');

    /* 
    // Presently disabled, using browserDetect.js method
    if ($.browser.msie) {
    if ($.browser.version == 6) {
    $('link:last').after('<link title="IE6 hacks" rel="stylesheet" type="text/css" href="styles/hacks-ie6.css" media="screen" />');
    }
    if ($.browser.version == 7) {
    $('link:last').after('<link title="IE7 hacks" rel="stylesheet" type="text/css" href="styles/hacks-ie7.css" media="screen" />');
    }
    if ($.browser.version == 8) {
    $('link:last').after('<link title="IE8 print hacks" rel="stylesheet" type="text/css" href="styles/print-ie8.css" media="print" />');
    }
    }
    */

    /*
    form enhancements - watermark
    */



    /* Tabs
    -------------------------------------------------------------------------------------- */



    /* Show / Hide
    -------------------------------------------------------------------------------------- */

        //buy-yes/buy-yes-plan.html
	$('#plan-benefits-container .hide-show-content').hide();
	try {
		document.execCommand("BackgroundImageCache", false, true);
	} catch(err) {}

	$('#plan-benefits-container ul.benefits-list li.column-1 .cta a.toggle-content').click( function() {
		//$("div:animated").slideUp(1500, 'easeInOutBack');
		$("#plan-benefits-container .content-1").slideToggle(1500, 'easeOut');

		$("#plan-benefits-container .content-2").slideUp(1500, 'easeInOutBack');
		$("#plan-benefits-container .content-3").slideUp(1500, 'easeInOutBack');
		$("#plan-benefits-container .content-4").slideUp(1500, 'easeInOutBack');
		
		$('#plan-benefits-container ul.benefits-list li.column-1').toggleClass('active');
		$('#plan-benefits-container ul.benefits-list li.column-2').removeClass('active');
		$('#plan-benefits-container ul.benefits-list li.column-3').removeClass('active');
		$('#plan-benefits-container ul.benefits-list li.column-4').removeClass('active');	
			
		return false;
	});
	$('#plan-benefits-container .content-1 ul.benefit-details li.action-close a').click( function() {
		$("#plan-benefits-container .content-1").slideUp(1500, 'easeInOutBack');
		$('#plan-benefits-container ul.benefits-list li.column-1').toggleClass('active');
		return false;
	});
	
	
	
	$('#plan-benefits-container ul.benefits-list li.column-2 .cta a.toggle-content').click( function() {	
		//$("div:animated").slideUp(1500, 'easeInOutBack');
		$("#plan-benefits-container .content-2").slideToggle(1500, 'easeOut');

		$("#plan-benefits-container .content-1").slideUp(1500, 'easeInOutBack');
		$("#plan-benefits-container .content-3").slideUp(1500, 'easeInOutBack');
		$("#plan-benefits-container .content-4").slideUp(1500, 'easeInOutBack');
		
		$('#plan-benefits-container ul.benefits-list li.column-2').toggleClass('active');
		$('#plan-benefits-container ul.benefits-list li.column-1').removeClass('active');
		$('#plan-benefits-container ul.benefits-list li.column-3').removeClass('active');
		$('#plan-benefits-container ul.benefits-list li.column-4').removeClass('active');
		
		return false;
	});
	$('#plan-benefits-container .content-2 ul.benefit-details li.action-close a').click( function() {
		$("#plan-benefits-container .content-2").slideUp(1500, 'easeInOutBack');
		$('#plan-benefits-container ul.benefits-list li.column-2').toggleClass('active');
		return false;
	});
	

	$('#plan-benefits-container ul.benefits-list li.column-3 .cta a.toggle-content').click( function() {			
		$("#plan-benefits-container .content-3").slideToggle(1500, 'easeOut');
		$("#plan-benefits-container .content-1").slideUp(1500, 'easeInOutBack');
		$("#plan-benefits-container .content-2").slideUp(1500, 'easeInOutBack');
		$("#plan-benefits-container .content-4").slideUp(1500, 'easeInOutBack');
		
		$('#plan-benefits-container ul.benefits-list li.column-3').toggleClass('active');
		$('#plan-benefits-container ul.benefits-list li.column-2').removeClass('active');
		$('#plan-benefits-container ul.benefits-list li.column-1').removeClass('active');
		$('#plan-benefits-container ul.benefits-list li.column-4').removeClass('active');
		return false;
	});
	$('#plan-benefits-container .content-3 ul.benefit-details li.action-close a').click( function() {
		$("#plan-benefits-container .content-3").slideUp(1500, 'easeInOutBack');
		$('#plan-benefits-container ul.benefits-list li.column-3').toggleClass('active');
		return false;
	});
	

	$('#plan-benefits-container ul.benefits-list li.column-4 .cta a.toggle-content').click( function() {		
		$("#plan-benefits-container .content-4").slideToggle(1500, 'easeOut');
		$("#plan-benefits-container .content-1").slideUp(1500, 'easeInOutBack');
		$("#plan-benefits-container .content-3").slideUp(1500, 'easeInOutBack');
		$("#plan-benefits-container .content-2").slideUp(1500, 'easeInOutBack');
		
		$('#plan-benefits-container ul.benefits-list li.column-4').toggleClass('active');
		$('#plan-benefits-container ul.benefits-list li.column-2').removeClass('active');
		$('#plan-benefits-container ul.benefits-list li.column-3').removeClass('active');
		$('#plan-benefits-container ul.benefits-list li.column-1').removeClass('active');
		return false;
	});
	$('#plan-benefits-container .content-4 ul.benefit-details li.action-close a').click( function() {
		$("#plan-benefits-container .content-4").slideUp(1500, 'easeInOutBack');
		$('#plan-benefits-container ul.benefits-list li.column-4').toggleClass('active');
		return false;
	});

		
	
	//say-yes.html
    $('#create-p-baccount .step-one .content .content-box .hide-show-content').hide();
    	$('#create-p-baccount .step-one .content .content-box input.toggle-content').click( function() {
    		$("#create-p-baccount .step-one .content .content-box .hide-show-content").slideToggle("slow");
    		return false;
    	});

    	$('#create-p-baccount .step-two .content .content-box .hide-show-content').hide();
    	$('#create-p-baccount .step-two .content .content-box input.toggle-content').click( function() {
    		$("#create-p-baccount .step-two .content .content-box .hide-show-content").slideToggle("slow");
    		return false;
    	});
    

    //FAQ, IDD-SMS-Rates
	$('.accordion-content-box1').hide();
	$("#billing-faqs .faq-group1 .title-box1").click( function() {
		var link = $(this).find('a.billing-faqs-toggle1');
		var link2 = $(this).find('div.faq-title');

		link.toggleClass('active', 100);
		link2.toggleClass('active', 100);

		$(this).siblings(".accordion-content-box1").slideToggle('slow');
		return false;
	});

	$('.accordion-content-box2').hide();
	$("#billing-faqs .faq-group2 .title-box2").click( function() {	
		var link = $(this).find('a.billing-faqs-toggle2');
		var link2 = $(this).find('div.faq-title');
		
		link.toggleClass('active', 100);
		link2.toggleClass('active', 100);

		$(this).siblings(".accordion-content-box2").slideToggle('slow');
		return false;
	});	

	$('.accordion-content-box3').hide();
	$("#billing-faqs .faq-group3 .title-box3").click( function() {	
		var link = $(this).find('a.billing-faqs-toggle3');
		var link2 = $(this).find('div.faq-title');
		
		link.toggleClass('active', 100);
		link2.toggleClass('active', 100);

		$(this).siblings(".accordion-content-box3").slideToggle('slow');
		return false;
	});	
	
	$('.accordion-content-box4').hide();
	$("#billing-faqs .faq-group4 .title-box4").click( function() {	
		var link = $(this).find('a.billing-faqs-toggle4');
		var link2 = $(this).find('div.faq-title');
		
		link.toggleClass('active', 100);
		link2.toggleClass('active', 100);

		$(this).siblings(".accordion-content-box4").slideToggle('slow');
		return false;
	});	
	
	$('.accordion-content-box5').hide();
	$("#billing-faqs .faq-group5 .title-box5").click( function() {	
		var link = $(this).find('a.billing-faqs-toggle5');
		var link2 = $(this).find('div.faq-title');
		
		link.toggleClass('active', 100);
		link2.toggleClass('active', 100);

		$(this).siblings(".accordion-content-box5").slideToggle('slow');
		return false;
	});	
	
	$('.accordion-content-box6').hide();
	$("#billing-faqs .faq-group6 .title-box6").click( function() {	
		var link = $(this).find('a.billing-faqs-toggle6');
		var link2 = $(this).find('div.faq-title');
		
		link.toggleClass('active', 100);
		link2.toggleClass('active', 100);

		$(this).siblings(".accordion-content-box6").slideToggle('slow');
		return false;
	});	
	
	$('.accordion-content-box7').hide();
	$("#billing-faqs .faq-group7 .title-box7").click( function() {	
		var link = $(this).find('a.billing-faqs-toggle7');
		var link2 = $(this).find('div.faq-title');
		
		link.toggleClass('active', 100);
		link2.toggleClass('active', 100);

		$(this).siblings(".accordion-content-box7").slideToggle('slow');
		return false;
	});	

    /* Form Enabler (Turns normal fields into forms when an 'edit' button/link is clicked)	
    -------------------------------------------------------------------------------------- */


    /* Dialog modal windows (lightbox)
    -------------------------------------------------------------------------------------- */

    $('a.dialog.view-video-intro-to-yes').click(function() {
        // show video in lightbox
        viewVideo('view-video-intro-to-yes', this.href);
        // prevent the default action
        return false;
    });

    $('a.dialog.view-video-yes-network').click(function() {
        // show video in lightbox
        viewVideo('view-video-yes-network', this.href);
        // prevent the default action
        return false;
    });

    $('a.dialog.view-video-yes-id').click(function() {
        // show video in lightbox
        viewVideo('view-video-yes-id', this.href);
        // prevent the default action
        return false;
    });

    $('a.dialog.view-video-yes-life').click(function() {
        // show video in lightbox
        viewVideo('view-video-yes-life', this.href);
        // prevent the default action
        return false;
    });
	
	$('a.dialog.view-video-yes-life2').click(function() {
        // show video in lightbox
        viewVideo('view-video-yes-life2', this.href);
        // prevent the default action
        return false;
    });
	
	$('a.dialog.view-video-yes-plan').click(function() {
        // show video in lightbox
        viewVideo('view-video-yes-plan', this.href);
        // prevent the default action
        return false;
    });
	
	$('a.dialog.view-video-yes-revolution').click(function() {
        // show video in lightbox
        viewVideo('view-video-yes-revolution', this.href);
        // prevent the default action
        return false;
    });

    $('a.dialog.view-video-yes-experience').click(function() {
        // show video in lightbox
        viewVideo('view-video-yes-experience', this.href);
        // prevent the default action
        return false;
    });
	
	$('a.dialog.view-video-yes-statement').click(function() {
        // show video in lightbox
        viewVideo('view-video-yes-statement', this.href);
        // prevent the default action
        return false;
    });

	$('a.dialog.view-video-compare-3g-4g').click(function() {
        // show video in lightbox
        viewVideo('view-video-yes-compare-3g-4g', this.href);
        // prevent the default action
        return false;
    });

    $('a.dialog.view-coverage').click(function() {
		callAnalytics('prodInteract','coverage_map');
        // fill in variables below
        var portletWidth = 1050;
        var portletHeight = 580;
        // don't edit the below unless necessary
        // instantiate the dialog on click event
        var portletTitle = $(this).attr('title');
        var portletContentURL = $(this).attr('href');
        var $dialog = $('<div id="dialog-window"><div style="width: 100%; text-align: center; display: table; height: 100%;"><div style="vertical-align: middle; display: table-cell;"><img src="/en/images/preloader.gif"></div></div></div>')
			.load(portletContentURL + ' .ytlc-portlet', function() {
			    //Cufon.refresh();
			})
			.dialog({
			    title: portletTitle,
			    autoOpen: false,
			    width: portletWidth + 16,
			    height: portletHeight + 120,
			    modal: true,
			    resizable: false,
			    draggable: false,
			    close: function() {
			        $dialog.dialog('destroy');
			        $('#dialog-window').remove();
			    },
			    focus: function() {
			        //Cufon.refresh();
			    }
			});
        // call .dialog('open') after the dialog has been instantiated	
        $dialog.dialog('open');
        // prevent the default action
        return false;
    });

	$('a.dialog.prepaid-rates').click(function() {
		callAnalytics('prodInteract','compare-prepaid-rates');
        // fill in variables below
        var portletWidth = 640;
        var portletHeight = 300;
        // don't edit the below unless necessary
        // instantiate the dialog on click event
        var portletTitle = $(this).attr('title');
        var portletContentURL = $(this).attr('href');
        var $dialog = $('<div id="dialog-window"><div style="width: 100%; text-align: center; display: table; height: 100%;"><div style="vertical-align: middle; display: table-cell;"><img src="/en/images/preloader.gif"></div></div></div>')
			.load(portletContentURL + ' #container-dialog-content', function() {
			    //Cufon.refresh();
			})
			.dialog({
			    title: portletTitle,
			    autoOpen: false,
			    width: portletWidth + 16,
			    height: portletHeight + 120,
			    modal: true,
			    resizable: false,
			    draggable: false,
			    close: function() {
			        $dialog.dialog('destroy');
			        $('#dialog-window').remove();
			    },
			    focus: function() {
			        //Cufon.refresh();
			    }
			});
        // call .dialog('open') after the dialog has been instantiated	
        $dialog.dialog('open');
        // prevent the default action
        return false;
    });

	$('a.dialog.postpaid-rates').click(function() {
		callAnalytics('prodInteract','compare-postpaid-rates');
        // fill in variables below
        var portletWidth = 640;
        var portletHeight = 300;
        // don't edit the below unless necessary
        // instantiate the dialog on click event
        var portletTitle = $(this).attr('title');
        var portletContentURL = $(this).attr('href');
        var $dialog = $('<div id="dialog-window"><div style="width: 100%; text-align: center; display: table; height: 100%;"><div style="vertical-align: middle; display: table-cell;"><img src="/en/images/preloader.gif"></div></div></div>')
			.load(portletContentURL + ' #container-dialog-content', function() {
			    //Cufon.refresh();
			})
			.dialog({
			    title: portletTitle,
			    autoOpen: false,
			    width: portletWidth + 16,
			    height: portletHeight + 120,
			    modal: true,
			    resizable: false,
			    draggable: false,
			    close: function() {
			        $dialog.dialog('destroy');
			        $('#dialog-window').remove();
			    },
			    focus: function() {
			        //Cufon.refresh();
			    }
			});
        // call .dialog('open') after the dialog has been instantiated	
        $dialog.dialog('open');
        // prevent the default action
        return false;
    });

	$('a.dialog.about-yes-mail').click(function() {
		callAnalytics('prodInteract','about-yes-mail');
        // fill in variables below
        var portletWidth = 640;
        var portletHeight = 300;
        // don't edit the below unless necessary
        // instantiate the dialog on click event
        var portletTitle = $(this).attr('title');
        var portletContentURL = $(this).attr('href');
        var $dialog = $('<div id="dialog-window"><div style="width: 100%; text-align: center; display: table; height: 100%;"><div style="vertical-align: middle; display: table-cell;"><img src="/en/images/preloader.gif"></div></div></div>')
			.load(portletContentURL + ' #container-dialog-content', function() {
			    //Cufon.refresh();
			})
			.dialog({
			    title: portletTitle,
			    autoOpen: false,
			    width: portletWidth + 16,
			    height: portletHeight + 120,
			    modal: true,
			    resizable: false,
			    draggable: false,
			    close: function() {
			        $dialog.dialog('destroy');
			        $('#dialog-window').remove();
			    },
			    focus: function() {
			        //Cufon.refresh();
			    }
			});
        // call .dialog('open') after the dialog has been instantiated	
        $dialog.dialog('open');
        // prevent the default action
        return false;
    });

	$('a.dialog.bizRegTy').click(function() {
		callAnalytics('prodInteract','business-register-ty');
        // fill in variables below
        var portletWidth = 640;
        var portletHeight = 100;
        // don't edit the below unless necessary
        // instantiate the dialog on click event
        var portletTitle = $(this).attr('title');
        var portletContentURL = $(this).attr('href');
        var $dialog = $('<div id="dialog-window"><div style="width: 100%; text-align: center; display: table; height: 100%;"><div style="vertical-align: middle; display: table-cell;"><img src="/en/images/preloader.gif"></div></div></div>')
			.load(portletContentURL + ' #container-dialog-content', function() {
			    //Cufon.refresh();
			})
			.dialog({
			    title: portletTitle,
			    autoOpen: false,
			    width: portletWidth + 16,
			    height: portletHeight + 120,
			    modal: true,
			    resizable: false,
			    draggable: false,
			    close: function() {
			        $dialog.dialog('destroy');
			        $('#dialog-window').remove();
			    },
			    focus: function() {
			        //Cufon.refresh();
			    }
			});
        // call .dialog('open') after the dialog has been instantiated	
        $dialog.dialog('open');
        // prevent the default action
        return false;
    });

    $('a.dialog.instructional-video').click(function() {
		callAnalytics('prodInteract','view-instructional-video');
        // fill in variables below
        var portletWidth = 640;
        var portletHeight = 450;
        // don't edit the below unless necessary
        // instantiate the dialog on click event
        var portletTitle = $(this).attr('title');
        var portletContentURL = $(this).attr('href');
        var $dialog = $('<div id="dialog-window"><div style="width: 100%; text-align: center; display: table; height: 100%;"><div style="vertical-align: middle; display: table-cell;"><img src="/en/images/preloader.gif"></div></div></div>')
			.load(portletContentURL + ' #container-dialog-content', function() {
			    //Cufon.refresh();
			})
			.dialog({
			    title: portletTitle,
			    autoOpen: false,
			    width: portletWidth + 16,
			    height: portletHeight + 120,
			    modal: true,
			    resizable: false,
			    draggable: false,
			    close: function() {
			        $dialog.dialog('destroy');
			        $('#dialog-window').remove();
			    },
			    focus: function() {
			        //Cufon.refresh();
			    }
			});
        // call .dialog('open') after the dialog has been instantiated
        $dialog.dialog('open');
        // prevent the default action
        return false;
    });


    $('a.dialog.7-tips').click(function() {
		callAnalytics('prodInteract','compare-7-tips');
        // fill in variables below
        var portletWidth = 640;
        var portletHeight = 400;
        // don't edit the below unless necessary
        // instantiate the dialog on click event
        var portletTitle = $(this).attr('title');
        var portletContentURL = $(this).attr('href');
        var $dialog = $('<div id="dialog-window"><div style="width: 100%; text-align: center; display: table; height: 100%;"><div style="vertical-align: middle; display: table-cell;"><img src="/en/images/preloader.gif"></div></div></div>')
			.load(portletContentURL + ' #container-dialog-content', function() {
			    //Cufon.refresh();
			})
			.dialog({
			    title: portletTitle,
			    autoOpen: false,
			    width: portletWidth + 16,
			    height: portletHeight + 120,
			    modal: true,
			    resizable: false,
			    draggable: false,
			    close: function() {
			        $dialog.dialog('destroy');
			        $('#dialog-window').remove();
			    },
			    focus: function() {
			        //Cufon.refresh();
			    }
			});
        // call .dialog('open') after the dialog has been instantiated	
        $dialog.dialog('open');
        // prevent the default action
        return false;
    });


	if ($("#find-a-store-select-town") && window.location.hash != "") {
		window.location.hash = window.location.hash;
		var namedSelector = "a[name=" + window.location.hash.substr(1).replace(" ", "-") + "]";
		var namedAnchor = $(namedSelector);
		if (!namedAnchor.siblings(".accordion-content-box1").is(":visible")) {
			namedAnchor.siblings(".title-box1").click();
		}
	}

	
});  // End document.ready()


function eppShareThankyou(URL) {
    // fill in variables below
    var portletWidth = 450;
    var portletHeight = 100;
    // don't edit the below unless necessary
    // instantiate the dialog on click event
    var portletTitle = $(this).attr('title');
    var portletContentURL = URL;
    var $dialog = $('<div id="dialog-window"><div style="width: 100%; text-align: center; z-index:2000; float:left; width: 660px; display: table; height: 100%;"><div style="vertical-align: middle; display: table-cell;"><img src="/en/images/preloader.gif"></div></div></div>')
			.load(portletContentURL + ' .ytlc-portlet', function() {
			    //Cufon.refresh();
			})
			.dialog({
			    title: portletTitle,
			    autoOpen: false,
			    width: portletWidth + 16,
			    height: portletHeight + 120,

			    modal: true,
			    resizable: false,
			    draggable: false,
			    close: function() {
			        $dialog.dialog('destroy');
			        $('#dialog-window').remove();
			    },
			    focus: function() {
			        //Cufon.refresh();
			    }
			});
    // call .dialog('open') after the dialog has been instantiated	
    $dialog.dialog('open');
    // prevent the default action
    return false;
}

function eppThankyou(URL) {
    // fill in variables below
    var portletWidth = 604;
    var portletHeight = 150;
    // don't edit the below unless necessary
    // instantiate the dialog on click event
    var portletTitle = $(this).attr('title');
    var portletContentURL = URL;
    var $dialog = $('<div id="dialog-window"><div style="width: 100%; text-align: center; display: table; height: 100%;"><div style="vertical-align: middle; display: table-cell;"><img src="/en/images/preloader.gif"></div></div></div>')
			.load(portletContentURL + ' .ytlc-portlet', function() {
			    //Cufon.refresh();
			})
			.dialog({
			    title: portletTitle,
			    autoOpen: false,
			    width: portletWidth + 16,
			    height: portletHeight + 120,
			    modal: true,
			    resizable: false,
			    draggable: false,
			    close: function() {
			        $dialog.dialog('destroy');
			        $('#dialog-window').remove();
			    },
			    focus: function() {
			        //Cufon.refresh();
			    }
			});
    // call .dialog('open') after the dialog has been instantiated	
    $dialog.dialog('open');
    // prevent the default action
    return false;
};




/**
* View videos in a lightbox 
*/
function viewVideo(videoName, videoURL) {
		callAnalytics('play_video', videoName);
		// fill in variables below
		var portletWidth = 660;
		var portletHeight = 455;
		// don't edit the below unless necessary
		// instantiate the dialog on click event
		var portletContentURL;
		if (videoURL) {
			portletContentURL = videoURL;
		} else {
			portletContentURL = '/en/dialog/' + videoName + '.html';
		}
//		var $dialog = $('<div id="dialog-window"><div style="width: 100%; text-align: center; display: table; height: 100%;"><div style="vertical-align: middle; display: table-cell;"><img src="/en/images/preloader.gif"></div></div></div>')
		var $dialog = $('<div id="dialog-window"></div>');
		var $preloader = $('<div id="dialog-preloader" style="background-color: #FFFFFF; position:absolute; z-index:2000; float:left; width: 660px; text-align: center; display: table; height: 506px; top: 30px;"><div style="vertical-align: middle; display: table-cell;"><img src="/en/images/preloader.gif"></div></div>');
		$preloader.appendTo($dialog);
			$dialog.dialog({
				title: '',
				autoOpen: false,
				width: portletWidth + 16,
				height: portletHeight + 120,
				modal: true,
				resizable: false,
				draggable: false,
				open: function() {
					$('iframe').hide();
				},
				close: function() {
					$dialog.dialog('destroy');
					$('#dialog-window').remove();
					$('iframe').show();
				},
				focus: function() {
					//Cufon.refresh();
				}
			});
			
		var $dialogcontent = $('<div></div>');
			$dialogcontent.load(portletContentURL + ' #container-dialog-view-video',function() {
				$dialogcontent.ready(function(responseText, textStatus, xhr) {
					$dialog.append($dialogcontent);
					//Cufon.refresh();
					$('#dialog-preloader').remove();
				});
			});
		// call .dialog('open') after the dialog has been instantiated	
		$dialog.dialog('open');
	}
	
/**
* share on twitter
*/
function shareVideoOnFacebook(videoName, title) {
	shareFacebook(getVideoShareURL(videoName), title);
}

function shareFacebook(url, title) {
	callAnalytics('engageParticipate', 'share_twitter');
	var socialURL = 'http://www.facebook.com/sharer.php?u=' + URLEncoder.encode(url) + '&t=' + URLEncoder.encode(title);
	window.open(socialURL, '_blank');
}

/**
* share on twitter
*/
function shareVideoOnTwitter(videoName, title) {
	shareTwitter(getVideoShareURL(videoName), title);
}

function shareTwitter(url, title) {
	callAnalytics('engageParticipate', 'share_facebook');
	var socialURL = 'http://www.twitter.com/share?url=' + URLEncoder.encode(url) + '&text=' + URLEncoder.encode(title);
	window.open(socialURL, '_blank');
}

function getVideoShareURL(videoName) {
	var url = window.location.href
	var anchorIndex = url.indexOf('#');
	if (anchorIndex >= 0) {
		url = url.substr(0, anchorIndex);
	}
	return url + '#' + videoName;
}


