$(function () {
	/*$('.menu>li').each (function () {
		$(this).children ('ul').css ('left', '-' + ($(this).position ().left - 200) + 'px');
		$(this).children ('ul').children ('li:last').find ('span').css ('background-image', 'none');
	});*/
	
	var join_text = '<span class="tweet_hilite">@digicelcricket</span> :';
	
	$('#tweets').tweet ({
		join_text: 'auto',
		username: 'digicelcricket',
		avatar_size: null,
		count: 6,
		auto_join_text_default: join_text, 
		auto_join_text_ed: join_text,
		auto_join_text_ing: join_text,
		auto_join_text_reply: join_text,
		auto_join_text_url: join_text,
		loading_text: "loading tweets...",
		show_date: true

	});
	
	$('.close').click (function () {
		$(this).parent ().slideUp ('fast');
	});
		
	$('#flickr').jflickrfeed ({
		limit : 1,
		qstrings : {
			id : '48212341@N02'
		},
		itemTemplate :  '<div style="float: left; width: 99%; padding: 5px 0;">' +
						'<div class="floatl" style="padding: 0 5px 0 0;">' +
						'<img src="{{image_s}}" alt="{{title}}" border="0" style="width: 55px; height: 55px;" />' +
						'</div>' +
						'<p class="red" style="padding: 3px 0; text-align: left;"><a href="{{link}}" target="_blank">{{title}}</a></p>' +
						'<p class="gray">{{published}}</p>' +
						'<div class="clearl">&nbsp;</div>' +
						'</div>'
	},
	function () {
		$(this).append ('<p style="text-align: right;"><a href="http://www.flickr.com/photos/digicelcricket/with/5655665530/">View Album</a></p><div class="clear">&nbsp;</div>');
	});
	
	$('.tabbed_content_control a').click (function () {
		$('.tabbed_content_control a').removeClass ('active');
		$(this).addClass ('active');
		if ($(this).attr ('href').indexOf ('#') === 0) {
			$('.tabbed_content').hide ();
			$($(this).attr ('href')).show ();
			return false;
		}
	});
	
	$('.poll').each (function () {
		var $results = $(this).find ('.poll-results');
		var $control = $(this).find ('.poll-control');
		
		$results.hide ();
		
		var $toresults = $('<a>').attr ('href', '#').text ('View Results!').appendTo ($control).bind ('click.poll', function () {
			$results.show ();
			$control.hide ();
			return false;
		});
		
		var $tocontrols = $('<a>').attr ('href', '#').text ('Cast Vote!').appendTo ($results).bind ('click.poll', function () {
			$control.show ();
			$results.hide ();
			return false;
		});
	});
});

function smart_pop_up (url, name, width, height){
	if (typeof (width) == 'undefined') width = screen.width - 100;
	if (typeof (height) == 'undefined') height = screen.height - 100;
	
	var win_width = screen.width - 100 < width ? screen.width - 100 : width;
	var win_height = screen.height - 100 < height ? screen.height - 100 : height;
	
	var x_pos = Math.ceil ((screen.width - win_width) / 2);
	var y_pos = Math.ceil ((screen.height - win_height) / 2);
	
	var is_image = url.match (/(jpg|gif|jpeg|png|JPG|GIF|JPEG|PNG){1}$/);
	var is_yt = url.match (/(youtube)/);
	var create_doc = is_image || is_yt;
	
	var new_window = window.open(create_doc ? 'about:blank' : url, '', 'location=no,toolbar=no,adressbar=no,statusbar=no,scrollbars=no,width=' + win_width + ',height=' + win_height + ',top=' + y_pos + ',left=' + x_pos);
	
	if (create_doc) {
		with (new_window.document) {
			writeln ('<html>');
			writeln ('<head>');
			writeln ('<title>' + name + '</title>');
			writeln ('<style type="text/css">body{margin:0px;}</style>');
			writeln ('<meta http-equiv="imagetoolbar" content="false">')
			writeln ('</head>');
			writeln ('<body>');
			if (is_image) {
				writeln('<img src="' + url + '" alt="' + name + '">');
			}
			else if (is_yt) {
				var qs = url.substr (url.indexOf ('?'), url.length);
				var ytcodel = qs.indexOf ('&') > 0 ? qs.indexOf ('&') : qs.length;
				var ytcode = qs.substr (qs.indexOf ('v=') + 2, ytcodel);
				writeln('<iframe title="YouTube video player" class="youtube-player" type="text/html" width="' + width + '" height="'+ height +'" src="http://www.youtube.com/embed/'+ ytcode +'" frameborder="0" allowFullScreen></iframe>');
			}
			writeln ('</body>');
			writeln ('</html>');
			close ();
		}
	}
	
	return false;
}

