﻿var flashwindow = 'null';
var newswindow = 'null';
var settings = 'width=' + $(window).width() + ',height=' + $(window).height() + ',scrollbars=yes,location=yes,directories=yes,status=yes,menubar=yes,toolbar=yes,resizable=yes';

function openFlash(link) {
	//alert("window.opener: " + window.opener + " flashwindow.closed: " + flashwindow.closed);
	if(window.opener) {
		//alert('focus on opener (from openFlash)');
		window.opener.blur(); //Chrome fix
		window.opener.focus();
	}
	else if((flashwindow != 'null') && (!flashwindow.closed))
	{
		//alert('focus on flash window');
		flashwindow.blur(); //Chrome fix
		flashwindow.focus();
	}
	else {
		//alert('open new window with flash');
		flashwindow = window.open(link,'flwin',settings);
		flashwindow.focus();
	}
}

function openNews(link) {
    
	//alert("window.opener: " + window.opener + " newswindow.closed: " + newswindow.closed);
	if(window.opener) {
	    //alert('focus on opener (from openNews)');
	    window.location = link;
		window.opener.blur(); //Chrome fix
		window.opener.focus();
	}
	else if((newswindow != 'null') && (!newswindow.closed))
	{
	    //alert('focus on news window');
	    newswindow.location = link;
		newswindow.blur(); //Chrome fix
		newswindow.focus();
	}
	else {
		//alert('open new window with news');
		newswindow = window.open(link,'newswin', settings);
		newswindow.focus();
	}
}

//alert(navigator.userAgent);


/* #DOM-READY
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
jQuery(function () {

    var userAgent = navigator.userAgent.toLowerCase();

    $('.tolink').bind('click', function () {
        if (!$.browser.opera && userAgent.indexOf("chrome") == -1 && !$.browser.safari) { // if not chrome or opera
            openFlash($('.tolink').attr('href'));
            return false;
        }
    });

    $('#preview01').bind('click', function () {
        var app = document.getElementById('PuffPreview')
        app.previewPuff($('#ctl00_ContentPlaceHolder1_txtText_0').val());
        return false;
    });

    $('#preview02').bind('click', function () {
        var app = document.getElementById('PuffPreview')
        app.previewPuff($('#ctl00_ContentPlaceHolder1_txtText_1').val());
        return false;
    });

    $('#preview03').bind('click', function () {
        var app = document.getElementById('PuffPreview')
        app.previewPuff($('#ctl00_ContentPlaceHolder1_txtText_2').val());
        return false;
    });

    $('#previewTitle').bind('click', function () {
        var app = document.getElementById('PuffPreview');
        app.previewPuff($('#ctl00_ContentPlaceHolder1_txtFlashTitle').val());

        var app2 = document.getElementById('PuffFullPreview');
        app2.previewPuff($('#ctl00_ContentPlaceHolder1_txtFlashTitle').val());
        return false;
    });

});
