﻿
var gfxPre = skinpath + "gfx/"

$(document).ready(function() {

    //TOOLTIP IMAGE
    $('.ToolTip').hover(function(e) {
        $('.ToolTipImg').show();
    },
    function() {
     $('.ToolTipImg').hide();
    }
    );


    //CLIENTS===========================================================
    if ($('.clients').length != 0) {
        //making a link
        x = "<a href='http://tink.co.il/Home/לקוחות.aspx'>" + $('.menu LI.current').text() + "</a>";
        $('.menu LI.current').html(x);

        var clientsLI = $('.clients').html();
        $('.clients').remove();
        //adding to the menu
        var tempLI = "<ul class='level-1 clients'> " + clientsLI + "</ul>";


        //fixing menu classes to act as clicked
        $('.menu LI.current').append(tempLI)
        $('.menu LI.current').addClass("current-parent");
        $('.menu LI.current-parent').removeClass("current");
        $('.clients LI:first').addClass("current");


        //fixing showing portfolio
        $('.1_show').removeClass("clientimageLinks").addClass("imageLinks");
        $('.imageLinks LI:first').addClass("me");

        //fixing numbers portfolio
        $('.imageLinks a.shownumber').each(function(index) {
            listItem = index + 1;
            if ($(this).parent().hasClass("me")) {
                $(this).find("img.numImg").attr("src", gfxPre + "nums_" + listItem + ".gif");
            }
            else {
                $(this).find("img.numImg").attr("src", gfxPre + "nums_" + listItem + ".gif");
            }
        });

    }


    $(".clients LI").click(function() {
        $(".clients LI").removeClass("current");
        $(this).addClass("current");

        $(".imageLinks").addClass("clientimageLinks").removeClass("imageLinks");
        var num = $(this).find("span").text();
        $("." + num + "_show").removeClass("clientimageLinks").addClass("imageLinks");


        $('.imageLinks a.shownumber').each(function(index) {
            listItem = index + 1;
            if ($(this).parent().hasClass("me")) {
                $(this).find("img.numImg").attr("src", gfxPre + "nums_" + listItem + ".gif");
            }
            else {
                $(this).find("img.numImg").attr("src", gfxPre + "nums_" + listItem + ".gif");
            }
        });

        changeImage('.imageLinks a.shownumber:first');

    })


    //PORTFOLIO===========================================================

    //first image load
    if ($('.imageLinks a.shownumber').length != 0) {
        
        changeImage('.imageLinks a.shownumber:first');
    }
    else if ($('.textDiv').length != 0) {
        $('.textDiv LI').hide();
    }

    if ($('.imageLinks LI').length <= 1) {
        $('.imageLinks LI').css("display", "none")
    }


    $('.imageLinks a.shownumber, .clientimageLinks a.shownumber').click(function(event) {
        event.preventDefault();
        changeImage(this);
    });



    $('.imageLinks a.shownumber, .clientimageLinks a.shownumber').hover(
        function() {

            var listItem = $('.imageLinks li').index($(this).parent()) + 1;
            if ($(this).parent().hasClass("me")) {
            }
            else {
                $(this).find("img.numImg").attr("src", gfxPre + "nums_over_" + listItem + ".gif");
            }
        },

    	function() {
    	    var listItem = $('.imageLinks li').index($(this).parent()) + 1;
    	    if ($(this).parent().hasClass("me")) {
    	    }
    	    else {
    	        $(this).find("img.numImg").attr("src", gfxPre + "nums_" + listItem + ".gif");
    	    }
    	}
    );





});



//portfolio
function changeImage(WhoAmI) {
   
    //old num
    $('.textDiv LI').hide();
    var listItem = $('.imageLinks li').index($('LI.me')) + 1;
    $('LI.me IMG.numImg').attr("src", gfxPre + "nums_" + listItem + ".gif"); //takes color img off old number
    $('Li.me').removeClass("me");
   
   //new num
    $(WhoAmI).parent().addClass("me");
    listItem=$('.imageLinks li').index($('LI.me'))+1;
    $('LI.me IMG.numImg').attr("src", gfxPre + "nums_select_" + listItem + ".gif"); //puts color img on new number

    
   //all new vars needed
    var str = $(WhoAmI).attr("href");
    var splitStr = str.split("#");
    SrcIs = splitStr[0];
    CompanyIS = splitStr[1]
    CommentIS = $(WhoAmI).parent().find('.hide').html();
    var iAm;
    if (SrcIs == "") {
        iAm = "flash";
    } else {
        iAm = "graphic";
    }

    


    if ($('.graphic').attr("src") == "" && $("SPAN.flash").css("display")=="none") { //no pic / flash yet

        if (iAm == "graphic") {
            $('.graphic').attr("src", SrcIs);
            $('.graphic').attr("alt", CompanyIS);
            $('.graphic').fadeIn();
        } 
        else { //flash
            $('.flash').html($('.me .preload').html());
            var flashHeight = 200 - (parseInt($('.flash OBJECT').css("height")) / 2)
            var flashWidth = 295 - (parseInt($('.flash OBJECT').css("width")) / 2)
            $('.flash').css({ "top": flashHeight + "px", "left": flashWidth + "px" });
            $('.flash').fadeIn();
        }
    
       
      
    }
    else { // has pic or flash

        $('.' + iAm).fadeOut('fast', function() {
            if (SrcIs == "") {
                $('.graphic').css("display", "none");
                $('.flash').html($('.me .preload').html());
                var flashHeight = 200 - (parseInt($('.flash OBJECT').css("height")) / 2)
                var flashWidth = 295 - (parseInt($('.flash OBJECT').css("width")) / 2)
                $('.flash').css({ "top": flashHeight + "px", "left": flashWidth + "px" });
                $('.flash').fadeIn();
            } else {
                $('.flash').css("display", "none");
                $('.graphic').attr("src", SrcIs);
                $('.graphic').attr("alt", CompanyIS);
                $('.graphic').fadeIn();
            }

        });
    }
  
    $('.graphic_comment').html(CommentIS);
    
    //text
    $("." + CompanyIS).show()
}
//portfolio



//add to favorites
function bookmarksite(title,url){
	if (window.sidebar) // firefox
	    window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
	    var elem = document.createElement('a');
	    elem.setAttribute('href',url);
	    elem.setAttribute('title',title);
	    elem.setAttribute('rel','sidebar');
	    elem.click();
	} 
	else if(document.all)// ie
	    window.external.AddFavorite(url, title);
}

