/*
	javascript for idocument tutorials page.

	idocument_tutorials.js v1.0
	create on 2009-12-07 by Oscar Woo

*/

$(document).ready(function() {

	// enable tooltip for "download" element. use the "slide" effect 
    $("#b_download").tooltip({
    	effect: 'slide',
    	tip: '#download_tips',
    	position: "bottom center",
    	offset: [6,0]
    });  
    
    $("#b_purchase").tooltip({
    	effect: 'slide',
    	tip: '#purchase_tips',
    	position: "bottom center",
    	offset: [6,0]
    }); 
    
	$("a.tutorial_link_video").click(function(){	
		var href = $(this).attr('href');
		video_mode(href);
		return false;
	});
	
	$("a.tutorial_link_text").click(function(){
		var href = $(this).attr('href');
		text_mode(href);
	});
	

});

function video_mode(href){
	$("a.active").removeClass("active");
	if($("div#tutorials_viewer").attr("class") == "t_mode"){
		//Switch viwer to video mode
		$("div#viewer_top").attr("class","v_mode");
		$("div#page_header").attr("class","v_mode");
		$("div#page").attr("class","v_mode");
		$("div#tutorials_viewer").attr("class","v_mode");		
		
		//Show Video Player
		$("div#tutorials_viewer").empty();
		$("div#player").appendTo("div#tutorials_viewer");
		$("div#featured").appendTo("div#tutorials_viewer");
		$("div#player").show();
		$("div#featured").show();
				
		insertVideo($("div#player"), $("a.tutorial_link_video[href='"+ href +"']").attr("rel"));
		
		$("a.tutorial_link_video[href='"+ href +"']").addClass("active");
		//$.scrollToElement( $("div#container"));
	}else{
		insertVideo($("div#player"), $("a.tutorial_link_video[href='"+ href +"']").attr("rel"));
		$("a.tutorial_link_video[href='"+ href +"']").addClass("active");
		//$.scrollToElement( $("div#container"));
	}
}
	

function text_mode(href){
		$("a.active").removeClass("active");
		
		if($("div#tutorials_viewer").attr("class") == "v_mode"){
			//Switch viwer to text mode
			$("div#viewer_top").attr("class","t_mode");
			$("div#page_header").attr("class","t_mode");
			$("div#page").attr("class","t_mode");
			$("div#tutorials_viewer").attr("class","t_mode");
			
			//Hide Video Player
			$("div#player").hide();
			$("div#featured").hide();
			$("div#player").appendTo("div#page_header");
			$("div#featured").appendTo("div#page_header");
		}
		
		$("a.tutorial_link_text[href='"+ href +"']").addClass("active");
		
		var topic = href.substring(6);
		$("div#tutorials_viewer").load("tutorials/"+ topic +".html","", function(){
			$.scrollToElement( $("div#container"));
		});
}

function insertVideo(target, source){
	if($.browser.safari)
	{
		target.html(videoObj4html5(source,640, 480));
	}else{
		target.html(videoObj4html4(source,640, 495));
	}
}



/*
 * ScrollToElement 1.0
 * Copyright (c) 2009 Lauri Huovila, Neovica Oy
 *  lauri.huovila@neovica.fi
 *  http://www.neovica.fi
 *  
 * Dual licensed under the MIT and GPL licenses.
 */
(function($) {
    $.scrollToElement = function( $element, speed ) {

        speed = speed || 750;

        $("html, body").animate({
            scrollTop: $element.offset().top,
            scrollLeft: $element.offset().left
        }, speed);
        return $element;
    };

    $.fn.scrollTo = function( speed ) {
        speed = speed || "normal";
        return $.scrollToElement( this, speed );
    };
})(jQuery);

