/// <reference path="jquery-1.3.1-vsdoc.js" />
/// <reference path="swfobject-vsdoc.js" />
/// <reference path="sifr-vsdoc.js" />


$(document).ready(function() {


	//
	//var doc2_height = $("#div_middle_center").height();

	//if(doc2_height != null)
	//{
		//doc2_height = doc2_height - 434;
		//document.getElementById('doc2_content_right_bottom_td').style.height = doc2_height + 'px'; 

	//}

	//Set height of right_snarveier
	var main_height = $("#div_middle_center").height();
	var right_height = $("#right_doc_list").height();

	var prod_height = $("#prod_item").height();

	if(main_height != null)
	{
		var doc2_height = main_height - 434;

		if (document.getElementById('doc2_content_right_bottom_td') != null)
		{

			document.getElementById('doc2_content_right_bottom_td').style.height = doc2_height + 'px'; 
			
		}
	}


	if(main_height != null && right_height != null && main_height > right_height)
	{
		document.getElementById('right_doc_list').style.height = main_height + 'px'; 
		document.getElementById('div_snarveier').style.height = main_height + 'px';



		//document.getElementById('doc2_content_right_bottom_td').style.height = doc2_height + 'px'; 
	}

	else if(prod_height != null && right_height != null && prod_height < right_height)
	{
		document.getElementById('prod_item').style.height = right_height + 'px'; 
		document.getElementById('div_middle_center').style.height = right_height + 'px';
	}


    var thisImg = "";
    var thisImg2 = "";


    //drop down right menu
    $('.btn-slide').bind("click", function() {
        $(".menu_" + this.id).slideToggle(300);

    });

    // show/hide 'send forespørsel'
    $('.div_prodspes_top').bind("click", function() {
        $(".div_sendFor").slideToggle(300);

		if (($('.sendForButton').hasClass('sendForButton_on')))
		{
			$('.sendForButton').removeClass('sendForButton_on');
			$('.div_prodspes_top').addClass('div_prodspes_top_on');
		}
		else
		{
			$('.sendForButton').addClass('sendForButton_on');
			$('.div_prodspes_top').removeClass('div_prodspes_top_on');
		}
    });

    myObject = null;


    // drop down top menu ul
    $('.dropdown-menu', this).hover(
      function() {



          // if ul is down
          if (($('.down-list', this).hasClass('isdown') || $('.topMenuImage', this).hasClass('showred')) && (myObject == this)) {

          }

          else {

              myObject = this;

              // Make level 1 link red if not active
              var img = $('.topMenuImage', this).attr("src");

              // store imagepath for mouse out
              thisImg = img;

              // if not active
              if (img.indexOf("_on_") == -1) {

                  img = thisImg.replace(/0/g, "");
                  img = img.replace(/1/g, "");
                  img = img.replace(/2/g, "");
                  img = img.replace(/3/g, "");
                  img = img.replace(/4/g, "");
                  img = img.replace(/5/g, "");
                  img = img.replace(/6/g, "");
                  img = img.replace(/7/g, "");
                  img = img.replace(/8/g, "");
                  img = img.replace(/9/g, "");

                  img = img.substring(0, (img.length - 6));

                  var imageOn = img + "on_" + thisImg.substring(img.length, thisImg.length);

                  $('.topMenuImage', this).attr('src', imageOn);
              }


              $('.topMenuImage', this).addClass('showred');
              $('.down-list', this).addClass('isdown');



              // if folder is set to drop down
              if (this.id == "dropdown") {
                  $('.down-list', this).slideDown(100);
              }
          }
      },
        function() {

            //if ($('.down-list', this).hasClass('isdown') && $('.topMenuImage', this).hasClass('showred')) {
			if ($('.down-list', this).hasClass('isdown')) {

                if (this.id == "dropdown") {
                    $('.down-list', this).slideUp(100);
                }

                // small pause
				testObj = $('.down-list', this);
                setTimeout("testObj.removeClass('isdown')", 100);


                //if (thisImg != '') {
                //    $('.topMenuImage', this).attr('src', thisImg);
                //}

                //thisImg = "";
				//testObj2 = $('.topMenuImage', this);
                //setTimeout("testObj2.removeClass('showred')", 100);
            }

             if (thisImg != '') {
                 $('.topMenuImage', this).attr('src', thisImg);
             }

            thisImg = "";
			testObj2 = $('.topMenuImage', this);
            testObj2.removeClass('showred');
        }
    );

    // li (level 2 link)
    $(".menuItem").hover(
        function() {

            var img = $('.topMenuImage2', this).attr("src");

            // store imagepath for mouse out
            thisImg2 = img;

            // if not active or hover
            if (img.indexOf("_on_") == -1) {

                // Remove menu id from img string
                img = thisImg2.replace(/0/g, "");
                img = img.replace(/1/g, "");
                img = img.replace(/2/g, "");
                img = img.replace(/3/g, "");
                img = img.replace(/4/g, "");
                img = img.replace(/5/g, "");
                img = img.replace(/6/g, "");
                img = img.replace(/7/g, "");
                img = img.replace(/8/g, "");
                img = img.replace(/9/g, "");

                // Read to where menu id starts
                img = img.substring(0, (img.length - 6));

                // New img src with menu id
                var imageOn = img + "on_" + thisImg2.substring(img.length, thisImg2.length);

                // Set src of img
                $('.topMenuImage2', this).attr('src', imageOn);
            }
        }
        ,
        function() {
            // Set src of img to original
            $('.topMenuImage2', this).attr('src', thisImg2);
        }
    );
});
