// JavaScript Document
var nextPhrase = 1;
var phraseTexts = [];

function createLink (link_url, link_title, link_type)
{

        link_url = window.location.href;
	var u = encodeURIComponent(link_url);
	var t = encodeURIComponent(link_title);

	
	if ( link_type == "digg" )
		targetUrl = 'http://digg.com/submit?phase=2&url=' + u + '&title=' + t;
	
	else if ( link_type == "fb" )
		targetUrl = 'http://www.facebook.com/share.php?u=' + u + '&amp;t=' + t;
		
	else if ( link_type == "delicious" )
		targetUrl = 'http://delicious.com/post?v=5&amp;url=' + u + '&amp;title=' + t;

	else if ( link_type == "myspace" )
		targetUrl = 'http://www.myspace.com/index.cfm?fuseaction=postto&' + 't=' + t + '&c=<p>www.jenkki.fi - ' + t + '</p>' + '&u=' + u + '&l=3';

	window.open(targetUrl);
}

$(document).ready(function()
{
	$(".phrase").each(function() { phraseTexts.push($(this).text()) });

	$('#goback').click(function()
	{
		history.back();
		return false;
	});

	$('#nexPhraseButton').click(function()
	{
		var i = 0;

		$(".phrase").each(function()
		{
			if ( i == nextPhrase )
			{
				$("#phraseToShow").css('display','none');
				$("#phraseToShow").removeAttr('id');
				$(this).css('display','block');
				$(this).attr( 'id', 'phraseToShow' );
			}
			i++;
		});

		nextPhrase = nextPhrase >= ( phraseTexts.length - 1 ) ? 0 : nextPhrase + 1;

		return false;
	});

});

function showLargePicture (thumbFilename, productName, productNumber)
{
	$('#product_details_link').attr( 'href', '/tuotekuvaus?id=' + productNumber );
	$('#product_picture_image').attr( 'href', '/tuotekuvaus?id=' + productNumber );
	$('#product_picture_h4_link').attr( 'href', '/tuotekuvaus?id=' + productNumber );
	$('#product_picture_image').html('<img src="/files/leaf/tuotekuvat/' + thumbFilename + '.png" alt="' + productName + '" />');
	$('#product_picture_h4_link').html(productName);

	return false;
}

function palautePopup() {
	/*jenkki_popup=window.open("http://palaute.leaf.fi/optimix/interview/Leaffifeed2.stm?passw=gt5rs&tau1=Jenkki.fi&tau4=Jenkki",'jenkki_popup','height=620,width=500,menubar=no,status=yes,location=no,toolbar=no,scrollbars=yes');
	if (window.focus) {jenkki_popup.focus()}*/
	window.open("http://palaute.leaf.fi/optimix/interview/Leaffifeed2.stm?passw=gt5rs&tau1=Jenkki.fi&tau4=Jenkki",'jenkki_popup','height=610,width=470,menubar=no,status=yes,location=no,toolbar=no,scrollbars=yes');
	return false;
}

function clearFormValue ( formfield )
{
	if ( formfield.defaultValue == formfield.value )
		formfield.value = "";
}

function resetFormValue ( formfield )
{
	if ( formfield.value == "" )
		formfield.value = formfield.defaultValue;
}