function OpenNewWindow(width,height,url) {
   
	windowWidth = width;
	windowHeight = height;
   
	resizable = '0';
	
	var centerWidth = (window.screen.width - windowWidth) / 2;
	var centerHeight = (window.screen.height - windowHeight) / 2;

	attribute = "resizable=" + resizable + ",width=" + windowWidth + ",height=" + windowHeight + ",left=" + centerWidth + ",top=" + centerHeight;
	window.open(url, "ndpviewer", attribute);
}

function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
 
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
 
    return vars;
}

function getUrlVarsFromUrl(url)
{
	var vars = [], hash;
    var hashes = url.slice(url.indexOf('?') + 1).split('&');
	
	//alert(hashes);
 
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
 
    return vars;
}

$(document).ready(function(){
	$(".content_category_wrapper").hover(function() {
		
		// Change title to date
		//ShowCategoryDate($(this).children(".content_category_title_wrapper"));
	});
	$(".content_category_wrapper").mouseleave(function() {
		// Change date to title
		//ShowCategoryTitle($(this).children(".content_category_title_wrapper"));
	});
	
	// Scroll page easing
	$('.scrollPage').click(function() {
		var elementClicked = $(this).attr("href");
		var destination = $(elementClicked).offset().top;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 1200,  'easeOutQuart' );
		return false;
	});
	
	$(window).scroll(function () { 
		$("html:not(:animated),body:not(:animated)").stop();
    });

});

function documentReady()
{
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal',
		//allowresize: false,
		default_width: 800,
		default_height: 600,
		theme: 'facebook',
		hideflash: false});
}

function bindPrettyPhoto()
{
	// Bind the code to each links
	$("a[rel^='prettyPhoto']").each(function(){
		$(this).bind('click',function(){
			_self = this; // Fix scoping
			
			// Find out if the picture is part of a set
			theRel = $(this).attr('rel');
			galleryRegExp = /\[(?:.*)\]/;
			theGallery = galleryRegExp.exec(theRel);
			
			// Build the gallery array
			var images = new Array(), titles = new Array(), descriptions = new Array();
			if(theGallery){
				$('a[rel*='+theGallery+']').each(function(i){
					if($(this)[0] === $(_self)[0]) setPosition = i; // Get the position in the set
					images.push($(this).attr('href'));
					titles.push($(this).find('img').attr('alt'));
					descriptions.push($(this).attr('title'));
				});
			}else{
				images = $(this).attr('href');
				titles = ($(this).find('img').attr('alt')) ?  $(this).find('img').attr('alt') : '';
				descriptions = ($(this).attr('title')) ?  $(this).attr('title') : '';
			}

			$.prettyPhoto.open(images,titles,descriptions);
			return false;
		});
	});
}
			
function ShowCategoryTitle(category)
{
	category.children("#content_category_title").addClass('content_category_visible');
	category.children("#content_category_title").removeClass('content_category_hidden');
	category.children("#content_category_titledate").addClass('content_category_hidden');
	category.children("#content_category_titledate").removeClass('content_category_visible');
}

function ShowCategoryDate(category)
{
	category.children("#content_category_title").addClass('content_category_hidden');
	category.children("#content_category_title").removeClass('content_category_visible');
	category.children("#content_category_titledate").addClass('content_category_visible');
	category.children("#content_category_titledate").removeClass('content_category_hidden');
}

/*if ($.browser.msie && parseInt($.browser.version) <= 6) {
	$(window).scroll(function() {
		$('#leftSideBar_container').css('top', $(this).scrollTop() + "px");
		$('#rightSideBar_container').css('top', $(this).scrollTop() + "px");
	});
	
	$(window).resize(function() {
		var container_w = 0;
		
		if ($(window).width() <= 800) {
			container_w = 800;
		} else if ($(window).width() >= 1024) {
			container_w = 1024;
		} else {
			container_w = $(window).width();
		}
		
		$('#container').css('width', container_w + "px");
	});
} else {

	$(window).load(function() {
		$('#leftSideBar_container').css('left', $('.leftCol').offset().left + "px");
		$('#rightSideBar_container').css('left', $('.rightCol').offset().left + "px");
	});
	
	$(window).resize(function() {
		var container_w = 0;
		
		if ($(window).width() <= 800) {
			container_w = 800;
		} else if ($(window).width() >= 1024) {
			container_w = 1024;
		} else {
			container_w = $(window).width();
		}
		
		$('#container').css('width', container_w + "px");
		
		$('#leftSideBar_container').css('left', $('.leftCol').offset().left + "px");
		$('#rightSideBar_container').css('left', $('.rightCol').offset().left + "px");
	});
}*/

var divId = -1;
var skipCount = 0;
var loaded = 0;

function getMore(id)
{
	divId ++;
	skipCount += 5;
	loaded = 0;
	hideLoadMore();
	$.get('loadmore.php?divid=' + (divId + 1) + '&skip=' + skipCount, receivedMore);
	$.get('loadmoreleft.php?divid=' + (divId + 1), receivedMoreLeft);
	$.get('loadmoreright.php?divid=' + (divId + 1), receivedMoreRight);
}

function receivedMore(data)
{
	$('#getMoreDiv' + divId).html(data);
	unhideDivs();
}

function unhideDivs()
{
	loaded ++;
	if (loaded == 3)
	{
		$('#getMoreDiv' + divId).animate({opacity: '1'}, 500);
		$('#getMoreDivLeft' + divId).animate({opacity: '1'}, 500);
		$('#getMoreDivRight' + divId).animate({opacity: '1'}, 500);
		$('#preloaderIcon').css('display', 'none');
		bindPrettyPhoto();
	}
}

function receivedMoreLeft(data)
{
	$('#getMoreDivLeft' + divId).html(data);
	unhideDivs();
}

function receivedMoreRight(data)
{
	$('#getMoreDivRight' + divId).html(data);
	unhideDivs();
}

function hideLoadMore()
{
	$('#loadMore').css('display', 'none');
	$('#preloaderIcon').css('display', 'block');
}

function showLoadMore()
{
	$('#loadMore').css('display', 'block');
}

function showArticleShare()
{
	if ($('.article_share_options').css('height') == '1px')
		$('.article_share_options').animate({ height: '72px' }, 500, 'swing');
	else
		$('.article_share_options').animate({ height: '1px' }, 500, 'swing');
}
