var $tujq = jQuery.noConflict();
$tujq(document).ready(function() {
	if ( typeof($tujq.tu_container_id) == "undefined" ) {
		$tujq.tu_container_id = 'tu_sw001';
	}
	if ( typeof($tujq.format) == "undefined" ) {
		$tujq.format = '300x600';
	}
	var tu_width;
	var tu_height;
	var tu_format;
	var tu_scrolling = 'no';
	var opt_linkdomain = '';
	if (typeof($tujq.linkdomain) != "undefined") {
		opt_linkdomain = '&amp;linkdomain=' + $tujq.linkdomain;
	}
	var opt_clicktrack = '';
	if (typeof($tujq.clicktrack) != "undefined") {
		opt_clicktrack = '&amp;clicktrack=' + $tujq.clicktrack;
	}
	switch ($tujq.format) {
	case '160x600':
		tu_width = '160';
		tu_height = '600';
		tu_format = 'twidget.2.160x600.html';
		break;
	case '160x600tt':
		tu_width = '160';
		tu_height = '600';
		tu_format = 'twidget.2.160x600tt.html';
		$tujq.format = '160x600';
		break;
	case '160x600tb':
		tu_width = '160';
		tu_height = '600';
		tu_format = 'twidget.2.160x600tb.html';
		$tujq.format = '160x600';
		break;
	case '300x600':
		tu_width = '300';
		tu_height = '600';
		tu_format = 'twidget.2.300x600.html';
		break;
	case '300x250':
		tu_width = '300';
		tu_height = '250';
		tu_format = 'twidget.2.300x250.html';
		break;
	case 'full':
		tu_width = '650';
		tu_height = '700'; // What to do?
		tu_format = 'twidget.2.full.html';
		tu_scrolling = 'auto';
		break;
	default:
		tu_width = '300';
		tu_height = '600';
		tu_format = '';
	}
	if ( $tujq('#' + $tujq.tu_container_id).length ) {
		// Find the location on that page
		var top_position = parseInt($tujq('#' + $tujq.tu_container_id).offset().top);
		var visible_height = parseInt($tujq(window).height());
		var above_fold = (top_position < visible_height) ? "Yes" : "No";
//        	$tujq('#' + $tujq.tu_container_id).append('<iframe name="twif91103" id="twif91103" src="http://localhost:8080/twidget/' + tu_format + '?partner=' + $tujq.partner + '&amp;keyword=' + $tujq.initial_keyword + '&amp;backfill=' + $tujq.backfill_keyword + '&amp;format=' + $tujq.format + '&amp;fold=' + above_fold + opt_linkdomain + opt_clicktrack + '" width="' + tu_width + '" height="' + tu_height + '" frameborder="0" marginwidth="0" marginheight="0" scrolling="' + tu_scrolling + '"></iframe>');
        	$tujq('#' + $tujq.tu_container_id).append('<iframe name="twif91103" id="twif91103" src="http://www.postup.com/t/html/' + tu_format + '?partner=' + $tujq.partner + '&amp;keyword=' + $tujq.initial_keyword + '&amp;backfill=' + $tujq.backfill_keyword + '&amp;format=' + $tujq.format + '&amp;fold=' + above_fold + opt_linkdomain + opt_clicktrack + '" width="' + tu_width + '" height="' + tu_height + '" frameborder="0" marginwidth="0" marginheight="0" scrolling="' + tu_scrolling + '"></iframe>');
	}
});
function retrieveKeywords() {
	var metatags = document.getElementsByTagName("meta");
	var keyword_string;
	var keywords;
	for (var i=0; i<metatags.length; i++) {
		if (metatags[i].name.toLowerCase() == 'keywords') {
			keyword_string = metatags[i].content;
		}
	}
	if (typeof(keyword_string) != "undefined" && keyword_string.length > 0) {
		keywords = keyword_string.split(/[,"]+/);
	} else {
		return;
	}
	return keywords[0];
}


