(function($unrulyJ) {
	$unrulyJ(document).ready(function(){
	
	function getFrameWidth() {
		if ($unrulyJ(window).height() > 800) {
			return 890;
		} else {
			return 750;
		}
	};
	
	function getFrameHeight() {
		if ($unrulyJ(window).height() > 800) {
			return 575;
		} else {
			return $unrulyJ(window).height() - 100;
		}
	};
	
	function getVideoWidth() {
		if ($unrulyJ(window).height() > 800) {
			return 854;
		} else {
			return 715;
		}
	};
	
	function getVideoHeight() {
		if ($unrulyJ(window).height() > 800) {
			return 505;
		} else {
			return getFrameHeight() - 65
		}
	};
	

	$unrulyJ('a.unruly_lightbox_link').each(function(){
		var iframe = '<iframe id="lightbox_video_'+new Date().getTime()+'" frameborder="0" src="'+$unrulyJ(this).attr("data-vvc-url")+'&width=' + getVideoWidth() + '&height=' + getVideoHeight() + '" width="' + (getFrameWidth() - 30) + '" height="' + (getFrameHeight() + 10) + '" style="border:none;overflow:hidden;"/>';
		$unrulyJ(this).qtip({
			content: {
				title: {
                    text: "<h2>"+$unrulyJ(this).attr("data-vvc-title")+"</h2>",
					button: 'Close X'
				}
          	},
          	position: {
             	target: $unrulyJ(document.body), // Position it via the document body...
             	corner: 'center' // ...at the center of the viewport
          	},
          	show: {
             	when: 'click', // Show it on click
             	solo: true // And hide all other tooltips
          	},
          	hide: { when: { event: 'unfocus' } },
         
        	style: {
          		'font-family': 'Lucida Grande',
				'font-size': '18px',
				'color': 'red',
    			width: getFrameWidth(),
    			height: getFrameHeight(),
             	padding: '10px 10px',
            	border: {
                    width: 9,
                    radius: 9,
                    color: '#666666'
                },
				title: {
					background:'#ffffff'
				},
                name: 'light'
    		},
			api: {
            	beforeShow: function(){
                	// Fade in the modal "blanket" using the defined show speed
                	$unrulyJ('#qtip-blanket').fadeIn(this.options.show.effect.length);
    				this.elements.content.html(iframe);
             	},
             	beforeHide: function(){
                	// Fade out the modal "blanket" using the defined hide speed
                	$unrulyJ('#qtip-blanket').fadeOut(this.options.hide.effect.length);
    				this.elements.content.html("<div/>");
             	}
          	}
		});
   });

   // Create the modal backdrop on document load so all modal tooltips can use it
   $unrulyJ('<div id="qtip-blanket">')
      .css({
         position: 'absolute',
         top: $unrulyJ(document).scrollTop(), // Use document scrollTop so it's on-screen even if the window is scrolled
         left: 0,
         height: $unrulyJ(document).height(), // Span the full document height...
         width: '100%', // ...and full width

         opacity: 0.7, // Make it slightly transparent
         backgroundColor: 'black',
         zIndex: 5000  // Make sure the zIndex is below 6000 to keep it below tooltips!
      })
      .appendTo(document.body) // Append to the document body
      .hide(); // Hide it initially
    });
})(jQuery);

