//cufon fonts
/*
$(document).ready(function() {
	Cufon.replace('h1.cufon-replace');
	Cufon.replace('h2.cufon-replace');
	Cufon.replace('h3.cufon-replace');
});
	
//old sifr fonts
$(document).ready(function() {
	if(typeof sIFR == "function"){
		sIFR.replaceElement(named({
			sSelector:"h2.akzidenz_grotesk",
			sFlashSrc: "" +baseUrl() +"/swf/akzidenz_grotesk.swf",
			sColor:"#5e6a71",
			sLinkColor:"#5e6a71",
			sBgColor:"#FFFFFF",
			sHoverColor:"#5e6a71",
			sFlashVars:"textalign=left&offsetTop=-2",
			sWmode: "transparent"
		}));

		sIFR.replaceElement(named({
			sSelector:"h1.akzidenz_grotesk",
			sFlashSrc: "" +baseUrl() +"/swf/akzidenz_grotesk.swf",
			sColor:"#5e6a71",
			sLinkColor:"#5e6a71",
			sBgColor:"#FFFFFF",
			sHoverColor:"#5e6a71",
			sFlashVars:"textalign=left&offsetTop=-2",
			sWmode: "transparent"
		}));
	};
});
 */
/* added by zaman */

$(document).ready(function() 
{
	
    if($('.ext-link').length > 0)
    {
        $('.ext-link').attr('target', '_blank');
    }
	
});

var currentImage = 1;
var numImages = 0;
var imageInterval = null;

$(function(){
    numImages = $("img.target-image").length;


    $("div.photo-gallery-left-content").hide();
    $("div#photo-gallery-left-content-id-1").show();

    $("span#single-image-container-id-1").addClass("image-gallery-item-selected");

    $("span.single-image-container").click(function(){
        $("span.single-image-container").removeClass("image-gallery-item-selected");
        var id = 0;
        if($(this).attr("id").match(/(^|\s)single-image-container-id-(\S+)(\s|$)/)) {
            id = RegExp.$2;
        }
        $("div.photo-gallery-left-content").hide();
        $("div#photo-gallery-left-content-id-" + id).show();

        $(this).addClass("image-gallery-item-selected");
    })

    $("span.single-image-container").hover(function(){
        $(this).addClass("image-gallery-item-change-bg");
    },
    function(){
        $(this).removeClass("image-gallery-item-change-bg");
    }
    )

    $("span#photo-gallery-pagination-prev a").click(function(){
        image_navigate('prev');
    })
    

    $("span#photo-gallery-pagination-next a").click(function(){        
        image_navigate('next')
    }
    )

    function image_navigate(op){
        var total_image = $("span.single-image-container").length;
        var current_selected_image_id = 0;
        var next_image_to_show = 0;

        if($("span.image-gallery-item-selected").attr('id').match(/(^|\s)single-image-container-id-(\S+)(\s|$)/)) {
            current_selected_image_id = RegExp.$2;
        }

        switch(op)
        {
            case 'next':
                if(current_selected_image_id == total_image){
                    next_image_to_show = 1;                    
                }else{
                    next_image_to_show = parseInt(current_selected_image_id) + 1;
                }
                break;
            case 'prev':
                if(current_selected_image_id == 1){
                    next_image_to_show = total_image;
                }else{
                    next_image_to_show = parseInt(current_selected_image_id) - 1;
                }
                break;
        }
       

        $("span.single-image-container").removeClass("image-gallery-item-selected");
        $("span#single-image-container-id-" + next_image_to_show).addClass("image-gallery-item-selected");

        $("div.photo-gallery-left-content").hide();
        $("div#photo-gallery-left-content-id-" + next_image_to_show).show();
    }
})

$('document').ready(function(){
    $('a[href*=#Kohde]').click(function(){
        $('.picture').css('background-color', 'transparent');
        if(imageInterval) window.clearInterval(imageInterval);

        $('.target-image').hide();
        imageInterval = window.setInterval("changeImage();", 4000);
    });

    $('a[href*=#Kohde]').click();
});

function changeImage(){
    $("img#target-image-" + currentImage).fadeOut("slow", function() {
        if (currentImage >= numImages){
                currentImage = 0;
        }
        $("img#target-image-" + (currentImage + 1) ).fadeIn("slow", function() {
                currentImage++;
        });

        $('.picture').css('background-color', 'white');
        $('.picture').height($("img#target-image-" + (currentImage + 1)).height());
    });
}

$('document').ready(function(){
    var current_selected_image_id = 0;
    var total_image = $(".area-image").length;
    $('.subpageLink').click(function(){
        
        if($(this).attr('id').match(/(^|\s)link-(\S+)(\s|$)/)) {
            current_selected_image_id = RegExp.$2;
        }
        
        $('.area-image').hide();
        $('#subpage-image-'+current_selected_image_id).show();
        $('.area-text').hide();
        $('#text-'+current_selected_image_id).show();

        $("li.subpageLink").removeClass("selected");
        $(this).addClass('selected');

         showhidenextprev(current_selected_image_id,total_image);
        return false;
    });
});

$('document').ready(function(){

    $('div#tabs a.next').click(function(){
        subpage_navigate('next');
        return false;
    })

    $('div#tabs a.previous').click(function(){
        subpage_navigate('prev');
        return false;
    })

});


function subpage_navigate(op){
    var total_image = $(".area-image").length;
    var current_selected_image_id = 0;
    var next_image_to_show = 0;

    if($("li.selected").attr('id').match(/(^|\s)link-(\S+)(\s|$)/)) {
        current_selected_image_id = RegExp.$2;
    }

    switch(op)
    {
        case 'next':
            if(current_selected_image_id == total_image){
                next_image_to_show = 1;
                
            }else{
                $('a.previous').show();
                next_image_to_show = parseInt(current_selected_image_id) + 1;
                
            }
            break;
        case 'prev':
            if(current_selected_image_id == 1){
                next_image_to_show = total_image;
            }else{
                next_image_to_show = parseInt(current_selected_image_id) - 1;
            }
            break;
    }

    showhidenextprev(next_image_to_show,total_image);
   
    $("li.subpageLink").removeClass("selected");
    $("#link-" + next_image_to_show).addClass("selected");

    $('.area-image').hide();
    $('#subpage-image-'+next_image_to_show).show();
    $('.area-text').hide();
    $('#text-'+next_image_to_show).show();

}

function showhidenextprev(curr,total){

 if(curr == 1){
        $('a.next').show();
        $('a.previous').hide();
    }

    if( curr == total)
    {
        $('a.next').hide();
        $('a.previous').show();
    }

    if( curr < total && curr > 1)
    {
        $('a.next').show();
        $('a.previous').show();
    }


}

