function shareTwitter(title, link){
  window.open('http://twitter.com/home?status=' + title + ': ' + link, 'share');
}
  function shareFacebook(title, link){
    window.open('http://www.facebook.com/sharer.php?u=' + link + '&t=' + title, 'share');
  }
  function shareDraugiem(title, link){
    window.open('http://www.draugiem.lv/say/ext/add.php?link=' + link + '&title=' + title + '&titlePrefix=zvaigzne.lv', 'share');
  }
function setGMDCookie(name, value, cokie_expire){
	var expire = new Date();
	expire.setTime( expire.getTime() + parseInt(cokie_expire) );
	var str = "GMD_" + name + "=" + value + "; expires=" + expire.toGMTString() + "; path=/";
	document.cookie = str;
}
function getGMDCookie( name ) {
	var prefix = "GMD_" + name + "=";
	var begin = document.cookie.indexOf( "; " + prefix );
	if ( begin == -1 ) {
		begin = document.cookie.indexOf( prefix );
		if ( begin != 0 ) {
			return false;
		}
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf( ";", begin );
	if (end == -1){
		end = document.cookie.length;
	}
	var result = unescape(document.cookie.substring(begin + prefix.length, end));
	return result;
}
var fontSize = 11;
var maxFontSize = 18;
var minFontSize = 11;
var resizeFont = function(pixels){
	$('#catalogProduct, .article').css('font-size', pixels + 'px');
	setGMDCookie('font_size', pixels, 30 * 24 * 60 * 60);
}
var decreaseFont = function(){
	fontSize --;
	if (fontSize < minFontSize){
		fontSize = minFontSize;
	}
	resizeFont(fontSize);
}
var increaseFont = function(){
	fontSize ++;
	if (fontSize > maxFontSize){
		fontSize = maxFontSize;
	}
	resizeFont(fontSize);
}
$(document).ready(function(){
	var storedSize = getGMDCookie('font_size');
	if (storedSize != false){
		fontSize = parseInt(storedSize);
		if (fontSize > maxFontSize){
			fontSize = maxFontSize;
		} else if (fontSize < minFontSize){
			fontSize = minFontSize;
		}
		resizeFont(fontSize);
	}
	$('select.per-page').change(function(){
		var loc = String(window.location);
		if (loc.indexOf('?') > 0){
			window.location = loc + '&per-page=' + $(this).val();
		} else {
			window.location = loc + '?per-page=' + $(this).val();
		}
	});
	$('a.lightbox').fancybox();
	$('img.fancy').parent('a').fancybox();
	$('#chart').tabs({
		selected: 0
	});
});
