﻿$(document).ready(function () {

	var location = $(window).attr('location').toString();

	//If we're working on localhost, subst the image.ashx
	if ((location.match("localhost") != null) ||
		(location.match("127.0.0.1") != null) ||
		(location.match("noozstaging.techaholics.gr" != null))) {
		$('img[src*=image.ashx]').attr('src', function () {
			return 'http://www.nooz.gr/' + $(this).attr('src');
		});

		$('img[src*=Uploads/]').attr('src', function () {
			return 'http://www.nooz.gr/' + $(this).attr('src');
		});
	}

    $("#fbFrame").hover(
        function(){$("#fbFrame").stop().animate({right:0},500);},
        function(){$("#fbFrame").stop().animate({right:-320},500);}
        );
});

// Add to favorites functionality
function addToFavorites() {
	var title = $('h1.title').html().trim();
	var url = window.location.href;

	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url, "");
	} else if (window.external) { // IE Favorite
		window.external.AddFavorite(url, title);
	} else if (window.opera && window.print) { // Opera Hotlist
		return true;
	}
}

// Send page via mail
function Mail() {
	document.location = "mailto:?subject=Nooz.gr - an article for you&Body=" + escape(window.location);
}

// Print current page
function do_print() {
	window.print();
	/*var agent = navigator.userAgent.toLowerCase();
	var isIE = agent.indexOf('msie') > -1 ? 1 : 0;
	var nw = window.open();
	var oDiv = document.getElementById('article_left_column');
	with (nw.document) {
	writeln('<html><head>');
	writeln('<title>' + document.title + '</title>');
	writeln('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">');
	writeln('</head>');
	writeln('<body>');
	writeln(oDiv.innerHTML);
	if (isIE) {
	writeln('<script language="javascript">');
	writeln('window.print();');
	writeln('<\/script>');
	}
	writeln('</body></html>');
	}
	if (isIE) {
	nw.location.reload();
	} else {
	nw.print();
	}
	nw.focus();*/
}


// Change font size
function ChangeFont() {
	// Get the pixel size of the font inside the article body
	var fontSize = parseInt($('.article_body_text').css('font-size').replace('px', ''));

	if (fontSize) {
		fontSize = fontSize + 2;
		if (fontSize > 18) { fontSize = 12; }
		$('.article_body_text')
			.stop()
			.animate({
				'fontSize': fontSize,
				'lineHeight': '1.5em'
			});
		// Set the FlashArticleFontSize cookie
		$.cookies.set('FlashArticleFontSize', fontSize);
	}
}

// Update bookmarks modal
function namechange_notification(){

    if ($.browser.msie && parseInt($.browser.version) <= 6) {
		
		alert("To Flash.gr έχει μετονομαστεί σε Nooz.gr\n\nΠαρακαλώ να πληκτρολογείτε τη νέα διεύθυνση, http://www.nooz.gr, καθώς επίσης να ενημερώσετε τους σελιδοδείκτες σας.\n\nΕυχαριστούμε για την κατανόηση!");
		
	} else {

		// Hide all iframes (various flash ads)
		$('iframe').css('visibility','hidden');
	
		// Open a simply modal dialog box
		$.modal($('.update_bookmarks_modal'), {
			opacity: 70,
			overlayCss: {
				backgroundColor: '#000',
				cursor: 'wait'
			},
			containerCss: {
				width: 520,
				backgroundColor: '#fff'
			}	
		});			
		
		// The close button for the modal dialog box
		$('.update_bookmarks_modal a.modalCloseImg').click(function(){
			$.modal.close();
			$('iframe').css('visibility','visible');			
		});
		
	}

}


// Page initialisation
$(function(){

	// On article page, check the FlashArticleFontSize cookie
	// and resize the text as needed
	if ($('div.article_body_text').length) {
		// Read cookie
		var fontSize = $.cookies.get('FlashArticleFontSize');
		if (!fontSize) { fontSize = 12; }
		$('div.article_body_text').css({
			'fontSize': fontSize,
			'lineHeight': '1.5em'
		});		
	}
		
	// Coming soon functionality
	// All links with class = "coming_soon" display a modal box
	$('a.coming_soon').click(function(e){
		e.preventDefault();
		
		// For IE6, simply show an alert box
		if ($.browser.msie && parseInt($.browser.version) <= 6) {
		
			alert("Λυπούμαστε αλλα η σελιδα / δυνατότητα αυτη δεν ειναι ακόμη διαθέσιμη.");
		
		} else {
		

			// Hide all iframess (various flash ads)
			$('iframe').css('visibility','hidden');
			
			// Open a simply modal dialog box
			$.modal($('.coming_soon_modal'), {
				opacity: 70,
				overlayCss: {
					backgroundColor: '#000',
					cursor: 'wait'
				},
				containerCss: {
					width: 520,
					backgroundColor: '#fff'
				}	
			});			
			
			// The close button for the modal dialog box
			$('a.modalCloseImg').click(function(){
				$.modal.close();
				$('iframe').css('visibility','visible');			
			});
			
			
		}
			
	});
		
});	
