window.onload = load;
function load() {
    //change the main div to overflow-hidden as we can use the slider now
    $('#scroll-pane').css('overflow','hidden');

    //calculate the height that the scrollbar handle should be
    var difference = $('#scroll-content').height()-$('#scroll-pane').height();//eg it's 200px longer 

    if(difference>0)//if the scrollbar is needed, set it up...
    {
       var proportion = difference / $('#scroll-content').height();//eg 200px/500px
       var handleHeight = Math.round((1-proportion)*$('#scroll-pane').height());//set the proportional height - round it to make sure everything adds up correctly later on
       handleHeight -= handleHeight%2; //ensure the handle height is exactly divisible by two

       $("#scroll-pane").after('<\div id="slider-wrap"><\div id="slider-vertical"><\/div><\/div>');//append the necessary divs so they're only there if needed
       $("#slider-wrap").height($("#scroll-pane").height()-29).css({'padding-bottom':29});


       //set up the slider 
       $('#slider-vertical').slider({
          orientation: 'vertical',
          range: 'max',
          min: 0,
          max: 100,
          value: 100,
          slide: function(event, ui) {
             var topValue = -((100-ui.value)*difference/100);
             $('#scroll-content').css({'margin-top':topValue});//move the top up (negative value) by the percentage the slider has been moved times the difference in height
          }
       });

       $(".ui-slider").css({'margin-top':29});
    }//end if
};

$(document).ready(function(){
    var menuWidth = $('#menu').width();
	var sum = 0;
    $('#menu .topmenu').each(function(e){
        var padding = $(this).css('padding-left').replace(/[^0-9]/g, "")*2;
        if($(this).parent().is('.last')){
            var lastWidth = menuWidth - sum - 1;
        	$(this).width(lastWidth - padding)
            $(this).parent().find('ul').width(lastWidth);
        } else {
            var width = $(this).width();
            var listWidth = $(this).parent().find('.submenu').width();
            if(width > listWidth-padding){
	            sum += width + padding +1;
	            $(this).parent().find('ul').width(width + padding);
            } else {
	            sum += listWidth+1;
	            $(this).width(listWidth);
	            $(this).parent().find('ul').width(listWidth);
	            $(this).width(listWidth - padding);
            }
        }
    });
    
    
//	$('.descModal').live('click',function(e){
//		e.preventDefault();
//		var text = $(e.target).parent().find('span').text();
//		$("#dialog").text(text);
//	    $("#dialog").dialog({modal: true, resizable: false});
//	});
	
	if($('a.lightbox').length > 0){
		$('a.lightbox').lightBox({fixedNavigation: true});
	}
	
	if ($('a.view').length > 0) {
		$('a.view').lightBox({withNavigation: false});
	}

	$("span.readMore").tooltip();
	
	$('.calculateinstallment').click(function(e)
        {
        	
        	e.preventDefault();
            var title = '';
            var filesrc = 'images/Raty_rowne_czy_malajace_642x790(2).swf';
            var width  = '820';
            var height = '790';
            var left   = (screen.width  - width)/2;
            var top    = (screen.height - height)/2;
            var params = 'width='+width+', height='+height;
            params += ', top='+top+', left='+left;
            params += ', directories=no';
            params += ', location=no';
            params += ', menubar=no';
            params += ', resizable=no';
            params += ', scrollbars=yes';
            params += ', status=no';
            params += ', toolbar=no';

            window11 = window.open('', +title, params);
            window11.document.write('<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" WIDTH='+width+' HEIGHT='+height+'><PARAM NAME=movie VALUE='+filesrc+'> <PARAM NAME=quality VALUE=high> <param name=\"wmode\" value=\"transparent\"> <EMBED src='+filesrc+' vmode=\"transparent\" quality=high WIDTH='+width+' HEIGHT='+height+' TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></EMBED></OBJECT>');
        });
	
	
});
