 $(document).ready(function(){
                // onHide : fade the window out, remove overlay after fade.
                var myClose = function(hash){
            		var $trigger = $(hash.t);
                    var $modal = $(hash.w);    
                    var $modalContent = $("iframe", $modal);
                    
//                    $modalContent.hide()//fadeOut('slow', function () {
//                    $modalContent.fadeOut('slow', function () {
//                						$modal.hide();//'slow', /*animate({width:($modal.width()/2), 
//                										height:($modal.height()/2), 
//                										top:(($(window).height() - $modal.height()/2)/2), 
//                										left:(($(window).width() - $modal.width()/2)/2)}
//                								, 500, 'linear',*/ function (){
										$modal.hide();
										hash.o.hide();//fadeOut('slow');
										$modalContent.html('').attr('src', '');//});//fadeOut('3000', function(){
//                    				});
                    
                    
                    
//                    });
                };
                var openInIframe = function(hash){
                    var newWidth = 0, newHeight = 0, newLeft = 0, newTop = 0;
                    var $trigger = $(hash.t);
                    var $modal = $(hash.w);
                    var myUrl = $trigger.children("#jqmIFrameUrl").text();
                    var myTitle = $trigger.attr('title');
                    var $modalContent = $("iframe", $modal);
                    
                    //$modalContent.html('').attr('src', '');
                    $modalContent.html('').attr('src', myUrl);
                    //let's use the anchor "title" attribute as modal window title
                    $('#jqmTitleText').text(myTitle);
                    
                    myUrl = (myUrl.lastIndexOf("#") > -1) ? myUrl.slice(0, myUrl.lastIndexOf("#")) : myUrl;
                    var queryString = (myUrl.indexOf("?") > -1) ? myUrl.substr(myUrl.indexOf("?") + 1) : null;
                    
                    if (queryString != null && typeof queryString != 'undefined') {
                        var queryVarsArray = queryString.split("&");
                        for (var i = 0; i < queryVarsArray.length; i++) {
                            if (unescape(queryVarsArray[i].split("=")[0]) == 'width') {
                                var newWidth = queryVarsArray[i].split("=")[1];
                            }
                            if (escape(unescape(queryVarsArray[i].split("=")[0])) == 'height') {
                                var newHeight = queryVarsArray[i].split("=")[1];
                            }
                        }
                        // let's run through all possible values: 90%, nothing or a value in pixel
                        if (newHeight != 0) {
                            if (newHeight.indexOf('%') > -1) {
                                newHeight = Math.floor(parseInt($(window).height()) * (parseInt(newHeight) / 100));
                            }
                            var newTop = Math.floor(parseInt($(window).height() - parseInt(newHeight)) / 2);
                        }
                        else {
                            newHeight = $modal.height();
                        }
                        if (newWidth != 0) {
                            if (newWidth.indexOf('%') > -1) {
                                newWidth = Math.floor(parseInt($(window).width() / 100) * parseInt(newWidth));
                            }
                            var newLeft = Math.floor(parseInt($(window).width() / 2) - parseInt(newWidth) / 2);
                            
                        }
                        else {
                            newWidth = $modal.width();
                        }
                       newTop -= 12; 
                        // do the animation so that the windows stays on center of screen despite resizing
                     
//                       $modalContent.hide();
                       $modal.jqmShow().css({ width: newWidth, height:newHeight, top:newTop, left:(newLeft - 11), marginLeft:0}).show();
//                       $modalContent.fadeIn('slow');

                       var tmp = $modalContent.offset().top - $modal.offset().top - 12;
                       $modalContent.height($modal.height());
                       $modal.height($modal.height() + tmp);
                       
                       
                       
//                       $modalContent.hide();
//                       $modal.css({ width:(newWidth/2), height:(newHeight/2), top:(($(window).height() - newHeight/2)/2), left:(($(window).width() - newWidth/2)/2), marginLeft:0});
//                       $modal.jqmShow().animate({ width: newWidth, height:newHeight, top:newTop, left:(newLeft - 11), marginLeft:0}, 1000, 'linear', 
//				                       function () {                       
//				                       		hash.w.children().fadeIn('slow');
//											var tmp = $modalContent.offset().top - $modal.offset().top - 12;
//											$modalContent.height($modal.height());
//											$modal.height($modal.height() + tmp);
//				                       });
                    } else {
                        // don't do animations
                        $modal.jqmShow().show();
                    }
                    
                }
                
          
                $('#modalWindow1').jqm({
                    modal: false,
                    trigger: 'div.jqtrigger, td.jqtrigger',
                    target: '#jqmContent1',
                    onHide: myClose,
                    onShow: openInIframe, 
                    overlay: 1
                });
                
                $('#modalWindow').jqm({
                    modal: false,
                    trigger: 'div.jqtrigger',
                    target: '#jqmContent',
                    onHide: myClose,
                    onShow: openInIframe, 
                    overlay: 1
                });
            });