<?xml version="1.0" encoding="UTF-8"?>
<Module>
    <ModulePrefs
            title="Featured Presentations"
            author="Nels Johnson"
            author_email="njohnson@downrecs.com"
            description="Featured Presentations">
        <Require feature="orng" />
        <Require feature="views" />
        <Require feature="flash" />
        <!-- Require feature="dynamic-height" / -->
        <Require feature="osapi" />
    </ModulePrefs>
    <Content type="html" view="default, home, profile"><![CDATA[<!--HTML-->
    <!DOCTYPE html>
    <base target="_blank"/>
    
    <!-- #includes -->
    <link rel="stylesheet" href="css/gadget.css" type="text/css" media="screen, projection">
    <link rel="stylesheet" href="css/inst.css" type="text/css" media="screen, projection" >
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js"></script>    
    <script type="text/javascript" src="js/os.js" ></script>
    
    <script type="text/javascript">
	    
	    function gotoSlideshare() {    		
	        var action = 'go_to_slideshare';
	        var href = $('div.ss-link a').attr('href');
    		gadgetEventTrack(action, href);
			window.top.location.href = href;
	    }
	    
	    function gadgetEventTrack(action, label, value) {
    		var message = {'action' : action};
    		if (label) {message.label = label;}
    		if (value) {message.value = value;}
			gadgets.orng.reportGoogleAnalyticsEvent(message);
            }
	    
	    // ========================================
	    function getUserNameAndPreview(userId){
			osapi.appdata.get({'userId': userId, 'groupId': '@self', 'appId':'@app', 'fields': ['username']})
		    	.execute(function(response){
		    		var viewer = os.osapi.getViewerFromResult(response);
		    		var username = viewer.username;
		    		$('input[name=username]').val(username);
		    		if(username != null && username != "") { // only render flash if there's a username
		    			preview(username);
		    		}	    				
		    });
		}
	    // ========================================
    
	    // ========================================
		function preview(username){
    		var url = "//static.slidesharecdn.com/swf/multiwidget.swf";
    			
 			$('#preview').html(
	 			'<div style="width:577px;margin:auto;">' +
	 				'<iframe src="//www.slideshare.net/' + username + 
	 				'/slideshelf" width="615px" height="470px" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:none;" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>' +
		    	'</div>'
	 		);   	
	 		
	    	$('div.ss-link a').click(function(event){
	    	    event.preventDefault();
	    		gotoSlideshare();	    		
	    	}); //click	 					
	    }
	    // ========================================
	    
	</script>
	    	
	    	
	<div id="secondHeader" style="display:none; margin:0px 10px 0px 10px;">
		<span class="slideshare_title"><b>SlideShare: A great way to share presentations</b></span>
	</div>
	
	<div id="settings" style="clear:both; margin:0px 10px 0px 10px;">	 
    </div>
    <br>
    <div id="preview">
    </div>
    ]]>
    </Content>
    <Content type="html" view="profile" preferred_height="500" preferred_width="590"><![CDATA[<!--HTML-->	
	    <script type="text/javascript">
		     // ========================================
	   		gadgets.util.registerOnLoadHandler(function(){
	    		getUserNameAndPreview('@owner');
	    	}); // registerOnLoadHandler    	
	    	// ========================================	
		</script>
    ]]>
    </Content>
    <Content type="html" view="home" preferred_height="725" preferred_width="700"><![CDATA[<!--HTML-->	
		<div id="inner_home_settings" style="display:none;">
			<p class="slideshare_body">
			If you already have a SlideShare account and have uploaded presentations, simply follow these steps:<br>
			</p>
			<p class="slideshare_body" style="padding-left:20px;">
			<ol>
				<li class="slideshare_body">Enter your SlideShare Username below and click Save/Preview. 
				Any public presentations that you've uploaded to SlideShare will be shown in the preview below.</li>
				<li class="slideshare_body">Make sure these presentations are the ones you want to share on your profile.</li>
				<li class="slideshare_body">Click the "Show" link (above, upper right) to make the presentations publicly available within your profile.</li>
				<li class="slideshare_body">To remove the presentations, delete your SlideShare Username and click Save/Preview. 
				Make sure to "Hide" your presentations from the public if you delete your SlideShare Username.</li>
			</ol>
			</p>
		    <div class="question">
				<span class="slideshare_body">SlideShare Username:&nbsp;</span><input type="text" name="username" style="display:inline;width:20em;">
				&nbsp;&nbsp;&nbsp;</span>
				<span class="save slideshare_body" title="Save this Username and preview the presentations.">Save/Preview</span>
				<br><br>
				<span class="slideshare_body">Don't have a SlideShare account yet? 
				Go to <a href="http://www.slideshare.net" target="_blank" title="Go to the SlideShare Web site">
				SlideShare</a> now to create an account and upload presentations.</span>
			</div>
		</div>
			
	    <script type="text/javascript">
		     // ========================================
	   		gadgets.util.registerOnLoadHandler(function(){
	    		var innerDiv=$('#inner_home_settings').html();
	    		$('#settings').html(innerDiv);
	    		
	    		$('#secondHeader').show();
	    		
	    		getUserNameAndPreview('@viewer');

		    	$('span.save').click(function(){
	    			var username = $('input[name=username]').val();
	    			osapi.appdata.update({'userId': '@viewer', 'groupId': '@self', 'appId':'@app', 'data':{'username':username} })
	    				.execute(function(response){
	    				});
	    				
	    				$('#preview').html('');
	    				if(username != null && username != "") {
	    					preview(username);
	    				}
		    	}); //click
	    	}); // registerOnLoadHandler    	
	    	// ========================================	
		</script>
		]]>
	</Content>
</Module>