var current_slider = 0;
var photoList =[];
var titleList =[];
var photoCur = 0;

/**
 * Executed when document is finished loading elements into DOM
 */
$(document).ready(function()
{
	/**
	 * Display confirmation dialog whenever link
	 * with className "confirm" is slicked
	 */
	$(".confirm").click(function(){
		return confirm("Vai tiešām vēlaties veikt šo darbību?");
	});
	
	
	
	$("#CommentName").focus(function(){
        if ($(this).val() == "Segvārds")
        {
            $(this).val("");
        }
    });

    $("#CommentName").blur(function(){
        if ($(this).val() == "")
        {
            $(this).val("Segvārds");
        }
    });
	
	$("#CommentEmail").focus(function(){
        if ($(this).val() == "E-pasts")
        {
            $(this).val("");
        }
    });

    $("#CommentEmail").blur(function(){
        if ($(this).val() == "")
        {
            $(this).val("E-pasts");
        }
    });
});

/**
 * Print email link (protection from spambots)
 * If javascript is disabled, nothing is visible
 *
 * @param string p1 Part 1 - this is username
 * @param string p2 Part 2 - this is domain and TLD
 */
function writemail(p1, p2)
{
	document.write("<a href='mailto:"+p1+"@"+p2+"'>"+p1+"@"+p2+"</a>");
}


/**
 * Load next slider
 *
 */
function loadNextSlider()
{
	if (++current_slider > $(".news-entry").length)
	{
		current_slider = 1;
	}

	setSliderPage(current_slider, false);

	slider_timer = setTimeout("loadNextSlider()", 10000);
}

function setSliderPage(n, manual)
{
	$(".news-entry").hide();
	$("#news-entry-"+n).show();

	$("#news-paginator a").removeClass("active");
	$("#news-paginator a#link-"+n).addClass("active");

	if (manual)
	{
		// stop automatic slider change if user manualy chooses slider
		clearTimeout(slider_timer);
	}
}

function loadGalleryImage(id)
{
	$("#main-gallery-image").attr("src", webroot+"img/galleries/medium/"+id+".jpg");
	
	 for (key in photoList)
	 {
		if(photoList[key] == id){photoCur = parseInt(key);}
	 }
	 
	$("#photo-title").text($("#title"+id).val());

}

function loadNextGalleryImage()
{
	if(photoCur < (photoList.length -1)){photoCur = photoCur + 1;}

	$("#main-gallery-image").attr("src", webroot+"img/galleries/medium/"+photoList[photoCur]+".jpg");
	
	$("#photo-title").text(titleList[photoCur]);

}

function loadPrevGalleryImage()
{
	if(photoCur >0){photoCur = photoCur - 1;}

	$("#main-gallery-image").attr("src", webroot+"img/galleries/medium/"+photoList[photoCur]+".jpg");
	
	$("#photo-title").text(titleList[photoCur]);

}

function DraugiemSay( title, url, titlePrefix ){
 window.open(
  'http://www.draugiem.lv/say/ext/add.php?title=' + encodeURIComponent( title ) +
  '&link=' + encodeURIComponent( url ) +
  ( titlePrefix ? '&titlePrefix=' + encodeURIComponent( titlePrefix ) : '' ),
  '',
  'location=1,status=1,scrollbars=0,resizable=0,width=530,height=400'
 );
 return false;
}
