   
    $(function() {
		$('.openwindow').click(function(e) {
		    var uid = $(this).attr("id").split(":")[0];
		    var index = $(this).attr("id").split(":")[1];
		    var clusterId = $(this).attr("id").split(":")[2];
		    $.post("Ajax/Links.ashx?uid=" + uid + "&index=" + index + "&clusterid=" + clusterId, 
		        function(data) {		
		            var prevLink = data.split(";")[0];
		            if (prevLink == "") 
		                $("#prevLink").hide(); 
		                else 
		                {
		                    $("#prevLink").show();
		                    $("#prevLink a").attr("id", prevLink.split("|")[0]);
		                    $("#prevLink a").attr("title", prevLink.split("|")[1]);
		                    $("#prevLink a").attr("href", prevLink.split("|")[2]);		                    
		                }
		                
		            var nextLink = data.split(";")[2];
		            if (nextLink == "") 
		                $("#nextLink").hide(); 
		                else 
		                {
		                    $("#nextLink").show(); 
		                    $("#nextLink a").attr("id", nextLink.split("|")[0]);
		                    $("#nextLink a").attr("title", nextLink.split("|")[1]);
		                    $("#nextLink a").attr("href", nextLink.split("|")[2]);		                    
		                }
		        }
		    );
		        
			e.preventDefault();			
			var $this = $(this);
			var horizontalPadding = 30;
			var verticalPadding = 90;
			
			var maxHeight = alertSize();
			var maxWidth = alertWidth();
			
			var defaultTitle = ($this.attr('title')) ? $this.attr('title') : 'Статья';
			
			$('#popupwindow').dialog({
	            title: defaultTitle,
	            autoOpen: true,	            	            
	            width: maxWidth - 50,
	            height: maxHeight - 50,
	            modal: true,
	            resizable: true,
				autoResize: true,
	            overlay: {
	                opacity: 0.5,
	                background: "black"
	            },
	            resizeStop: function(event, ui) 
	            {
	                var windowWidth =  $('#popupwindow').dialog( "option", "width" );
        			var windowHeight =  $('#popupwindow').dialog( "option", "height" );			
			        $('#frameWindow').width(windowWidth - horizontalPadding).height(windowHeight - verticalPadding);	
	            },
	            open: function()
	            {
	                getHeight('blockDiv');
	                blockDivSize();
	            }	            
	        });		   
	        
	        var windowWidth =  $('#popupwindow').dialog( "option", "width" );
			var windowHeight =  $('#popupwindow').dialog( "option", "height" );
			
			$('#frameWindow').attr('src', this.href).width(windowWidth - horizontalPadding).height(windowHeight - verticalPadding);	             
		});
		
		$("#prevLink").click(function() {
		    //$('#frameWindow').attr('src', $("input", this).val()); 		    
		});   
		
		$("#nextLink").click(function() {
		    //$('#frameWindow').attr('src', $("input", this).val()); 
		});  	

    });
    
        function blockDivSize()
		{
		    var image = $("#blockImage");
		    var div = $("#blockDiv");
		    $(image).css("width", $(div).css("width"));
		    $(image).css("height", $(div).css("height"));
		}
    
        function getHeight(elementName) {
		  //var iframeWin = window.frames[iframeName];
		  var varEl = document.getElementById? document.getElementById(elementName): document.all? document.all[elementName]: null;
		  if (varEl) {
		  varEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous
		  //var docHt = getDocHeight(iframeWin.document);
		  // need to add to height to be sure it will all show
		  var h = alertSize();
		  var new_h = (h-130);
		  varEl.style.height = new_h + "px";
		  //alertSize();
		  }
		}
    
        function alertSize() {
		  var myHeight = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
		    //Non-IE
		    myHeight = window.innerHeight;
		  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'
		    myHeight = document.documentElement.clientHeight;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		    //IE 4 compatible
		    myHeight = document.body.clientHeight;
		  }
		  //window.alert( 'Height = ' + myHeight );
		  return myHeight;
		}
		
		function alertWidth() {
		  var myWidth = 0;
		  if( typeof( window.innerWidth ) == 'number' ) {
		    //Non-IE
		    myWidth = window.innerWidth;
		  } else if( document.documentElement && (document.documentElement.clientWidth || document.body.clientHeight ) ) {
		    //IE 6+ in 'standards compliant mode'
		    myWidth = document.documentElement.clientWidth;
		  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		    //IE 4 compatible
		    myWidth = document.body.clientWidth;
		  }
		  //window.alert( 'Width = ' + myWidth );
		  return myWidth;
		}
    

