﻿// tooltips
var $jq3 = jQuery.noConflict();
this.tooltip = function(){	
	/* CONFIG */		
		xOffset = -10;
		yOffset = 5;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$jq3("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";	
		this.r = this.rel;
		this.rel = "";	
		$jq3("body").append("<p id='tooltip'>"+ this.r +"</p>");
		$jq3("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;
		this.rel = this.r;
		$jq3("#tooltip").remove();
    });	
	$jq3("a.tooltip").mousemove(function(e){
		$jq3("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

$jq3(document).ready(function(){
	tooltip();
});

//////////


var $jq2 = jQuery.noConflict();
$jq2(document).ready(function()  
{ 
	/* listojen/taulukoiden vuorottaiset solut yms */
	$jq2('table.show-listing tr').hover(function() {
		$jq2(this).addClass('hoverclass');
	}, function() {
		$jq2(this).removeClass('hoverclass');
	});
	
	
	$jq2("#sidebar .sidebar-box:first").addClass("first");
	$jq2(".news-list .news-item-short:even").addClass("alt-row");
	$jq2(".announcement-list .announcement-item-short:even").addClass("alt-row");
	$jq2(".zebraTable tr:even").addClass("alt-row");
	$jq2(".zebraTable tr:first").addClass("alt-first");
	$jq2("#search-results .ajaxSearch_result:odd").addClass("alt-row"); 


	/* Slideshow maintabs */
	$jq2("#slidetabs").idTabs(function(id,list,set){ 
    	$jq2("a",set).removeClass("selected") 
    	.filter("[@href='"+id+"']",set).addClass("selected"); 
    	for(i in list) 
      		$jq2(list[i]).hide(); 
    		$jq2(id).fadeIn(); 
    	return false; 
  	}); 
	
	/* lisätään tyhjä title kuville IE:tä varten */
	$jq2('#slideshow img').attr({
		title: ""					
	});
	
	/* luodaan linkit näytelmien nimistä */
	$jq2('#nav1 > li').wrapInner("<a href='#'></a>");
	$jq2('#nav2 > li').wrapInner("<a href='#'></a>");
    
	/* valikon näyttö/piilotus */
    $jq2('.wrap1').hover(
        function() { $jq2('#nav1').fadeIn(); },
        function() { $jq2('#nav1').fadeOut(); }
    );
    
	$jq2('.wrap2').hover(
        function() { $jq2('#nav2').fadeIn(); },
        function() { $jq2('#nav2').fadeOut(); }
    );
    
    
    $jq2('.wrap1 ul').hover(function() {
		$jq2(this).addClass('rollover');
	}, function() {
		$jq2(this).removeClass('rollover');
	});
	
	$jq2('.wrap2 ul').hover(function() {
		$jq2(this).addClass('rollover');
	}, function() {
		$jq2(this).removeClass('rollover');
	});
	

	/* kuvien rotaatio 1/2 */
   	$jq2('.pics1').cycle({
        fx: 'fade',
        speed:   650,
        timeout: 5000,
		pager:  '#nav1', 
		pause: true,
    	pagerAnchorBuilder: function(idx, slide) { 
        	return '#nav1 li:eq(' + idx + ') a'; 
    	} 
    });
	
	$jq2('.pics2').cycle({
        fx: 'fade',
        speed:   650,
        timeout: 5000,
		pager:  '#nav2', 
		pause: true,
    	pagerAnchorBuilder: function(idx, slide) { 
        	return '#nav2 li:eq(' + idx + ') a'; 
    	} 
    });
	
	/* control-painikkeiden blurri */
	$jq2('#slideshow a').click(function() {
		this.blur();
	});
	$jq2('#slideshow a').focus(function() {
		this.blur();
	});

});


/********* 
* Forms 
*********/

$jq = jQuery.noConflict();

$jq.fn.inputobserver = function() {
	return this.focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = '';
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
};

$jq(document).ready(function() {
	
	var jot_form = $jq("form.jot-form");
	if (jot_form.length > 0) {
		if ($jq("form.jot-form input[@name=name]").val().length < 1) {
			$jq("form.jot-form input[@name=name]").attr('defaultValue', 'Nimi').val('Nimi').inputobserver();
		}
		if ($jq("form.jot-form input[@name=email]").val().length < 1) {
			$jq("form.jot-form input[@name=email]").attr('defaultValue', 'Sähköpostiosoite').val('Sähköpostiosoite').inputobserver();
		}
		if ($jq("form.jot-form input[@name=title]").val().length < 1) {
			$jq("form.jot-form input[@name=title]").attr('defaultValue', 'Otsikko').val('Otsikko').inputobserver();
		}
		if ($jq("form.jot-form textarea[@name=content]").val().length < 1) {
			$jq("form.jot-form textarea[@name=content]").attr('defaultValue', 'Kommenttisi').val('Kommenttisi').inputobserver();
		}
	}
});

