﻿var IE = document.all?true:false;
var posx;
var posy;
function getMouse(event){
    posx=0;
    posy=0;
     
}

function view_thumb(event, imgsrc){
    document.getElementById("thumb_viewer").style.top = (event.clientY - 150) + "px";
    document.getElementById("thumb_viewer").style.left = (event.clientX  + 50)  + "px";
    document.getElementById("thumb_image").src=imgsrc;
    document.getElementById("thumb_viewer").style.visibility='visible';
        
}

function hide_thumb()
{
    document.getElementById("thumb_viewer").style.top = 0;
    document.getElementById("thumb_viewer").style.left = 0;
    document.getElementById("thumb_image").src="";
    document.getElementById("thumb_viewer").style.visibility='hidden';
}
function resizeThumb(img){
    if(img.width > 230){
	img.width = 230;
    }
    if(img.height > 120){
        img.height = 120;
    }
}
function showAlert(message){
    $('#aMsg').html(message);
    $('#alert-message').show();
    $('#message').fadeIn("fast");
    //setTimeout("hideMessages()",5000);
}
function showInfo(message){
    $('#iMsg').html(message);
    $('#info-message').show();
    $('#message').fadeIn("fast");
    //setTimeout("hideMessages()",1500);
}
function showSuccess(message){
    $('#sMsg').html(message);
    $('#success-message').show();
    $('#message').fadeIn("fast");
    setTimeout("hideMessages()",3000);
}
function hideMessages(){
    $('#alert-message').html("");
    $('#alert-message').hide();
    $('#info-message').html("");
    $('#info-message').hide();
    $('#success-message').html("");
    $('#success-message').hide();
    $('#message').fadeOut("slow")

}
function showMessage(msg,type){
    switch(type){
        case "info":
            $("body").append("<div id='message'><div id='info-message'><div id='iMsg'>" + msg + "</div><div><input type='button' class='btn' value='Sulje' onclick='hideMessage()' /></div></div></div>");
            $('#info-message').show();
            $('#message').fadeIn("fast");
            break;
        case "success":
            $("body").append("<div id='message'><div id='success-message'><div id='sMsg'>" + msg + "</div><div><input type='button' class='btn' value='Sulje' onclick='hideMessage()' /></div></div></div>");
            $('#success-message').show();
            $('#message').fadeIn("fast");
            setTimeout("hideMessage()",3000);
            break;
        case "alert":
            $("body").append("<div id='message'><div id='alert-message'><div id='aMsg'>" + msg + "</div><div><input type='button' class='btn' value='Sulje' onclick='hideMessage()' /></div></div></div>");
            $('#alert-message').show();
            $('#message').fadeIn("fast");
            break;
        default:
            break;
    }
}
function hideMessage(){
    $("#message").remove();
}
$(document).ready(function(){
    $('#main').fadeIn(500);
    $("#tabs").tabs({
        cookie: {}
    });
    //$("form.validate").validationEngine('attach');
    

    $("form.validate").each( function(){
        $(this).validate({
            onblur: true,
            focusInvalid:false,
            focusCleanup: true,
            errorPlacement: function(error, element) {
                error.insertBefore(element);
            }          
            
        });
    });
     $("div.accordion").each( function(){
        $(this).accordion({
            autoHeight: false,
            collapsible: true
        });
    });
    $("div.multiOpenAccordion").each( function(){
        $(this).multiOpenAccordion({          
        });
    });
   
    /*$('.datepickerclass').each(function(){
        $(this).datepicker({
            showOn: "button",
            buttonImage: "public/resources/icons/calendar.png",
            buttonImageOnly: true
	});
    });*/
    $('#helppi').dialog({autoOpen: false});
    $('#error-dialog').dialog({autoOpen: false});
    //$('#helppi').dialog('open');
});
function showPreview(thumb_src){
     var kerroin = 1;
     $("#preview").fadeIn("fast");
     var thumb_img = new Image();
     thumb_img.src = thumb_src.replace("._thumb","");
     thumb_img.onload = function(){
        if (thumb_img.width > (0.9 * $(window).width())){
            kerroin = thumb_img.width / (0.9 * $(window).width());
            thumb_img.width = thumb_img.width / kerroin;
            thumb_img.height = thumb_img.height / kerroin;
        }
        if (thumb_img.height > (0.9 * $(window).height())){
            kerroin = thumb_img.height / (0.9 * $(window).height());
            thumb_img.width = thumb_img.width / kerroin;
            thumb_img.height =  thumb_img.height / kerroin;
        }
        $("#preview_img").css("width", thumb_img.width);
        $("#preview_img").css("height", thumb_img.height);
        if ($(window).width() > thumb_img.width){
            $("#preview").css("left",(($(window).width() - thumb_img.width) / 2) + "px");
        }
        if ($(window).height() > thumb_img.height){
            $("#preview").css("top",(($(window).height() - thumb_img.height) / 2) + "px");
        }
        $("#preview_img").attr("src",thumb_img.src);
        
     };
}
function hidepreview(){
    $("#preview").fadeOut("fast");
    $("#preview_img").attr("src","public/resources/icons/LoadingIcon.gif");
    $("#preview_img").css("width", "20px");
    $("#preview_img").css("height", "20px");
    $("#preview").css("left","50%");
     $("#preview").css("top","50%");
}
function placeImg(img){
    // muutetaan ensin kuvan kokoa jos isompi kuin ruutu (pienentään 90% ruudun koosta)
    
}
function hideHelp(){
    $("#help").fadeOut("fast");
}


