


			
			;var gameData = { 
				width: 600, 
				height: 400 };
			
			function UpdateWidget( scope ) {	
				var width = 0;
				var height = 0;
				
				if( !scope) {
					scope = $(document);
				}
				
				if( width == "" ) {
					var size = $('[name=widget-size]:checked', scope ).val();
					
					switch( size ) {
						case "small": 
							width = parseInt( 600 * 0.3 );
							height = parseInt( 400 * 0.3 );
							break;
							
						case "medium":
							width = parseInt( 600 * 0.5 );
							height = parseInt( 400 * 0.5 );
							break;
			
						case "large":
							width = 600;
							height = 400;
							break;
			
						case "custom":
							var ratio = $( "#widget-size-slider", scope ).slider( 'value' );
							width = parseInt( 600 * ( ratio / 100 ) );
							height = parseInt( 400 * ( ratio / 100 ) );
							break;
					}
				}
				
				var container = $('<div></div>');
				container.attr( 'class', 'octogames-widget-frame-container' );
				container.attr( 'style', 'position:relative; text-align:center' );
				
				var frame = $( '<iframe></iframe>' );
				frame.attr('id', 'octogames-widget-frame');
				frame.attr('width', width);
				frame.attr('height', height);
				frame.attr('src', "http://online-jocuri.com/GameWidget/FrameContent.rails?contentLinkID=1213&width=" + width + "&height=" + height );
				
				var link = $( '<a></a>' );
				link.attr( 'class', 'octogames-widget-link' );
				link.attr( 'target', 'blank' );
				link.attr( 'style', 'display:block' );
			
				link.attr( 'title', 'Game Coolio dj' );
				                
				link.attr( 'href', 'http://online-jocuri.com/Joc+Coolio_dj+21213' );
				                
				link.text( 'Game Coolio dj' );
				
				container.append( frame );
				container.append( link );
				
				$( "#widget-preview", scope ).unbind( "click", ShowWidgetPreview );
				
				$( "#widget-preview", scope ).button( 'option', 'click', function() { 
					ShowWidgetPreview( { 
						width: width, 
						height: height
					} );
				} );
				
				$( "#custom-code", scope ).val( container.outerHTML() );
				$( "#custom-code", scope ).change();
			}
			
			function ShowWidgetPreview( data ) {
				powerOn.dialogManager.showDialog( { 
					id: 'widget-preview-dialog',
					url: "http://online-jocuri.com/GameWidget/Preview.rails",
					data: { 
						contentLinkID: 1213, 
						width: data.width, 
						height: data.height 
					},
					title: "Preview",
					closeable: true, 
					cache: false, 
					show_buttons: false, 
					cssClass: 'widget-preview-dialog', 
					width: 'auto'
				} );
			}
			
			function UpdateTimerText( seconds ) {
				$( "#game-preroll-stoper" ).show();
				$( '#game-preroll-timer' ).text( ( seconds ) + " Seconds" );
			}
			
			function updateLoginForFavoriteResults(data) {
				registerFavoriteGame( "Coolio dj has been added to your favorite games." );
									
				$( '#button-add-favorite-game' ).unbind( 'click' );
			}
			
			function initializeWidgetHandlers( scope ) {
			  	$( '#custom-code', scope ).click( function() 
			  	{
			  		this.select();
				});
			    
			    $( "#widget-size-large", scope ).click();
			    UpdateWidget( scope );
			
			    $( '#custom-code', scope ).autoResize();
			    $( '#custom-code', scope ).change();
			    
			    $( "#widget-size-slider", scope ).slider( 
			    { 
					max: 200, 
					min: 0, 
					step: 10, 
					value: 100,
					orientation: 'horizontal', 
					change: function() 
					{
						$( "#widget-size-custom", scope ).click();
						UpdateWidget( scope );
					}
				} );
			        
			    $( "[name=widget-size]", scope ).change( function() { 
					UpdateWidget( scope ); 
				} );
			}
			
			function registerFavoriteGame( message ) {
				$.post( 
					'http://online-jocuri.com/Profile/AddGameToFavorite.rails', 
					{
						contentLinkID: 1213, 
						width: $( '#game' ).width(), 
						height: $( '#game' ).height(), 
						successMessage: message
					}, 
					function( data ) {
						powerOn.showMessages( data.messages );
					}, 
					'json' );
			}
			
			function InitializePublicationButtons()
			{
				var text = "Coolio dj";
				
				$.ajax( {
					type: 'get', 
					url: 'http://json-tinyurl.appspot.com/', 
					data: { url: 'http://online-jocuri.com/Joc+Coolio_dj+21213' }, 
					success: function( response ) {
						$( '#button-share-facebook' ).attr( 'href', 'http://www.facebook.com/sharer.php?u=' + response.tinyurl + '&t=' + encodeURIComponent( text ) );
						$( '#button-share-twitter' ).attr( 'href', 'http://twitthis.com/twit?url=' + response.tinyurl + '&title=' + encodeURIComponent( text ) + '&prepend=' + encodeURIComponent( 'Check out:' ) );
					}, 
					dataType: 'jsonp' } );
			}
			
			$(document).ready(function()
			{		
			    $(window).resize(function(){
					CheckGameSize( gameData );
			    });
			
				$( ".ui-toolbar .ui-button" ).cluetip( { 
			  		local: true, 
			  		hideLocal: false, 
			  		arrows: true, 
			  		cursor: 'pointer'
			  	});
			  		
			    $( "#button-size-plus" ).button( 'option', 'click', function() {
						var game = $( '#game' );
						var width = game.width() * 1.10;
						var rightPosition = game.offset().left + width;
						
						if( rightPosition < $( ".content" ).width() ) {
							game.width( width );
							game.height( $( '#game' ).height() * 1.10 );
							
							sizeWasModified = true;
								
							CheckGameSize( gameData );
						}
				} );
			
			    $( "#button-size-minus" ).button( 'option', 'click', function() {
						var game = $( '#game' );
						game.width( game.width() / 1.10 );
						game.height( game.height() / 1.10 );
					    
						sizeWasModified = true;
						defaultSizeWasTooBig = false;
				} );
			
			    $( "#button-size-default" ).button( 'option', 'click', function() {
						var game = $( '#game' );
						game.width( 600 );
						game.height( 400 );
					    
						sizeWasModified = true;
						defaultSizeWasTooBig = false;
							
						CheckGameSize( gameData );
				} );
			    
			    $( ".button-help-screenshot" ).button( 'option', 'click', function() {
						powerOn.dialogManager.showDialog( { 
							url: "http://online-jocuri.com/Games/ChallengeResultHelp.rails",
							title: "How to take a screenshot",
							modal: false,
							closeable: true, 
							open: refreshPlugins, 
							show_buttons: false		
						} );
				});
			    
				$( '#button-publish, #game-link-publish' ).button( 'option', 'click', function() {
						if( $( '#game-widget .ui-accordion-header' ).attr( 'aria-expanded' ) == 'false' ) {
							$( '#game-widget' ).accordion( 'activate', 0 );
							$( '#game-widget' ).effect("pulsate", { times: 1 }, 800);
						}
				});	
					
				$( '#button-instructions' ).button( 'option', 'click', function() {
						if( $( '#game-instructions .ui-accordion-header' ).attr( 'aria-expanded' ) == 'false' )	{
							$( '#game-instructions' ).accordion( 'activate', 0 );
							$( '#game-instructions' ).effect("pulsate", { times: 1 }, 800);
						}
				});
			    
				$( '#button-more-games' ).button( 'option', 'click', function() {
						if( $( '#similar-games .ui-accordion-header' ).attr( 'aria-expanded' ) == 'false' )	{
							$( '#similar-games' ).accordion( 'activate', 0 );
							$( '#similar-games' ).effect("pulsate", { times: 1 }, 800);
						}
				});
			    
				$( '#button-challenge' ).button( 'option', 'click', function() {
						if( $( '#game-challenge .ui-accordion-header' ).attr( 'aria-expanded' ) == 'false' ) {
							$( '#game-challenge' ).accordion( 'activate', 0 );
							$( '#game-challenge' ).effect("pulsate", { times: 1 }, 800);
						}
				});
			    
			

    $( "#button-user-challenge" ).button( 'option', 'click', function() {
			powerOn.confirm( {
				message: "Please make sure you took a screenshot of the game with your score displayed as it will be requested to submit your score. If you did, click ok.", 
				confirmed: function() {
					
						window.location = 'http://online-jocuri.com/Login/Default.rails?backUrl=http%3a%2f%2fonline-jocuri.com%2fChallengesCreation%2fCreateUserChallenge.rails%3fuserID%3d0%26contentLinkID%3d1213';
					
				}	
			} );
	} );

    $( "#button-challenge-score" ).button( 'option', 'click', function() {
			powerOn.confirm( {
				message: "Please make sure you took a screenshot of the game with your score displayed as it will be requested to submit your score. If you did, click ok.", 
				confirmed: function() {
					window.location = 'http://online-jocuri.com/Games/ChallengeSubmitResult.rails?challengeSubscriptionID=0&contentLinkID=1213';
				}
			} );
    } );
    	
	$( '#button-add-favorite-game' ).button( 'option', 'click', function() {

				
					var message = 'Coolio dj has been added to your favorite games.';
			
								
			
				powerOn.navigate( 
					'http://online-jocuri.com/Login/Default.rails', {
						backurl: powerOn.makeUrl( 
							"http://online-jocuri.com/Profile/AddGameToFavorite.rails", {
								contentLinkID: 1213, 
								width: $( '#game' ).width(), 
								height: $( '#game' ).height(), 
								successMessage: message
							})				
					});
					
			
	});
	            
    var timerCount = 0;
    
    var timerMax = 10;
    
    UpdateTimerText( timerMax );
   	
    $( '#game-preroll-stoper' ).click( function() { 
		ShowGame( timer );
	});	
 
	var timer = $.timer( 1000, function ( timer ) {
		timerCount++;
		
		UpdateTimerText( timerMax - timerCount );
		
		if( timerCount == timerMax ) {
			ShowGame( timer );
		}
	});
	
	InitializePublicationButtons();
	
	initializeWidgetHandlers( $(document) );
	
	$( "#challengesSelector" ).change( function() {
		$( "#challengeResults" ).load( 
			"http://online-jocuri.com/Games/GetChallengeResultsForm.rails", 
			{ challengeSubscriptionID: $( this ).val() }, 
			function() { cmxform( { reset: true } ); } );
	});	
	
	$( "#challengesSelector" ).change();
});

function ShowGame( timer ) {	
	timer.stop();
		
	$( '#game-preroll' ).hide();
	$( '#game-zone' ).show();
	$( "#game-toolbar" ).show();

    
	
	
	
	
}
