/// <reference path="jquery-1.2.6-vsdoc.js" />

/*
 * main.js
 * Library: jquery 1.2.6
 * @Author: Eric Freeberg, bswing
 * @Date: 
 */

var ISEEK = {

    tabIds: new Array(),

   init:function()
   {
   		
        ISEEK.setSideBarSearch();
        ISEEK.setIntroSlideShow();
        ISEEK.setExpandCollapsePane();
        ISEEK.setShareMenu();
        ISEEK.modalBox();
        ISEEK.setTipBalloons();
//        ISEEK.setTabs();
        ISEEK.initSearchPage();		
    }
   ,
   getIntroSlide:function(id)
   {
   
            // identify new slide
            var fade_in_target;         
             $(".intro-slide").each( function(e){
                 if(e == id)
                 {
                    fade_in_target = this;
                 }
             });
            

            // fade out existing slide 
            $(".intro-slide").each( function(e){
               
               if($(this).css("display") == "block")
               {
                    $(this).fadeOut(100,function()
                    {
                        // fade in target slide once fadeOut is complete
                        $(fade_in_target).fadeIn(300);  
                    }); 
               }
           
           }); 
           
           // update the selected navigation display
           $("#intro-slide-nav a").each( function(e){
            
               if(e == id)
               {
                  $(this).addClass("current");
               }
               else
               {
                  $(this).removeClass("current");
               }
           
           });
       
  
     
   }
   ,
   initSearchPage: function()
   {
        if ($("body.search").length > 0)
        {
            $("#keyword-expandable").find("h3 span").addClass("expand"); 
            $("#keyword-expandable").find("h3 span").removeClass("collapse");
                
            var detail = $("#keyword-expandable div.search-subset-content");
            var arrow = $(this).find("span");
            
            if($(detail).css("display") == "none")
            {
                $(arrow).addClass("expand"); 
                $(arrow).removeClass("collapse"); 
                $(detail).slideDown(300);
            }
            else
            {
                $(arrow).addClass("collapse"); 
                $(arrow).removeClass("expand"); 
                $(detail).slideUp(300);
            }
        }
   }
   ,

  setExpandCollapsePane:function()
   {
/* Remove this section when we change the collapsible sections */
         // common
/*        $(".sub-info").each(
            function(i){
                $(this).find(".sub-info-detail").css("display","none");
                $(this).find("h3 span").addClass("collapse"); 
                $(this).find("h3 span").removeClass("expand");
                $(this).find("h3").click(
                    function(e){
                        
                        var detail = $(this).next(".sub-info-detail");
                        var arrow = $(this).find("span");
                        
                        if($(detail).css("display") == "none")
                        {
                            $(arrow).addClass("expand"); 
                            $(arrow).removeClass("collapse"); 
                            $(detail).slideDown(300);
                        }
                        else
                        {
                            $(arrow).addClass("collapse"); 
                            $(arrow).removeClass("expand"); 
                            $(detail).slideUp(300);
                        }
                    }
                );
            }
        );
*/        
        // Search
        $(".search-subset").each(
            function(i)
            {
                $(this).find(".search-subset-content").css("display","none");
                $(this).find("h3 span").addClass("collapse"); 
                $(this).find("h3 span").removeClass("expand");
                $(this).find("h3").click(
                    function(e)
                    {
                        var detail = $(this).next(".search-subset-content");
                        var arrow = $(this).find("span");
                        
                        if($(detail).css("display") == "none")
                        {
                            $(arrow).addClass("expand"); 
                            $(arrow).removeClass("collapse"); 
                            $(detail).slideDown(300);
                        }
                        else
                        {
                            $(arrow).addClass("collapse"); 
                            $(arrow).removeClass("expand"); 
                            $(detail).slideUp(300);
                        }
                    }
                );
            }
        );

}

   ,
   setIntroSlideShow:function()
   {
       // display only the first slide
       var intro_slide_show =  $(".intro-slide");
       for(var s = 0; s < intro_slide_show.length; s++)
       {
            // open the first one
            if(s == 0)
            {
                $(intro_slide_show[s]).css("display","block");
            }
            else
            {
               $(intro_slide_show[s]).css("display","none");
            }
        }
       
       // set click event on the navigation
       $("#intro-slide-nav a").each( function(e){
           $(this).click(function(){
                ISEEK.getIntroSlide(e); 
           });
       });
       
   }
    , 
    
    setShareMenu:function()
    {
        $("ul.xoperation").addClass("operation");
        $("ul.xoperation").removeClass("xoperation");
        
        /*
        $("li.share").click(
            function()
            {
                var dialog = $(this).find("div");
                if($(dialog).css("display") == "none")
                {
                    $(dialog).slideDown(300);
                }
            }
        );
        */
        
        $("a.share-link").click(
            function()
            {
                //var dialog = $("li.share").find("div");
                
                var li = $(this).parent();
                var dialog = li.find("div");
                
                if($(dialog).css("display") == "none")
                {
                    $(dialog).slideDown(300);
                }
                else
                {
                    $(dialog).slideUp(300);
                }
            }
        );

        $(".share-menu .close").click(
            function()
            {
                $(this).parents(".share-menu").slideUp(300);
            }
        );
    }
    ,
   setSideBarSearch:function()
   {
       // find all search boxes on page
       var side_search_box =  $(".search-box");
       
       for(var s = 0; s < side_search_box.length; s++)
       {
            // open the first one           
            if(s == 0)
            {
                $(side_search_box[s]).find(".input-fields").css("display","block");
                $(side_search_box[s]).find("span").removeClass("collapse");
                $(side_search_box[s]).find("span").addClass("expand");
            }
            else
            {
               $(side_search_box[s]).find(".input-fields").css("display","none");
               $(side_search_box[s]).find("span").removeClass("expand");
               $(side_search_box[s]).find("span").addClass("collapse");
            }
            
            // update the click event for each search box

             $(side_search_box[s]).find("h3").click(
                function(){
                                   
                   var obj = $(this).next(".input-fields");
                                     
                   if(obj.css("display") == "none")
                   {
                        $(this).next(".input-fields").slideDown(400);
                        $(this).find("span").removeClass("collapse");
                        $(this).find("span").addClass("expand");
                   }
                   else
                   {
                        $(this).next(".input-fields").slideUp(400);
                        $(this).find("span").removeClass("expand");
                        $(this).find("span").addClass("collapse");
                   }  
                }
             );
       } 
   }
   ,
   setTabs: function()
    {
        if ($(".tabs").length > 0)
        {
            $(".tabs .tabs-nav").tabs();
        }
    }
    ,
    setTipBalloons:function()
    {
// Remove 'if' statement so it can be used across the site when needed
//        if ( ($("body.skills").length > 0) || ($("body.search").length > 0) || ($("body.detail-content").length > 0)   || ($("body.search-results").length > 0)  )
//        {
            // Swap classes, to enable JavaScript enhancement.
            $("a.xtip-link").addClass("tip-link");
            $("a.xtip-link").removeClass("xtip-link");
            
            // Hide the tip balloons.
            $("a.tip-link span.tip").css("display", "none");
            
            $("a.tip-link").click(function()
            {
                
                
                if ($(this).find("span.tip").css("display") == "none")
                {
                    $("span.tip").css("display", "none");
                    $(this).find("span.tip").css("display", "block");
                    return false;
                }
                else
                {
                    $(this).find("span.tip").css("display", "none");
                    return false;
                }
            });
//        }
    }
    ,
   modalBox:function()
   {
        if($('#videoOverlay').length > 0)
        {
            $('#videoOverlay').jqm({
                onShow: function(h) {
                    
                    h.o.css("display","none");
                    h.o.fadeIn(
                        
                        function(){ 
                            h.w.css('opacity',1).slideDown();
                        }
                    
                    );
                   // alert("test");
                    /* callback executed when a trigger click. Show notice */
                   //  
                  }
                  ,
                   onHide: function(h) {
                    
                   // alert("test");
                    /* callback executed when a trigger click. Show notice */
                    h.w.css('opacity',0.92).slideUp( function(){ h.o.fadeOut() }); 
                  }
            });
        }   
   }
}


$(document).ready(function () {
    ISEEK.init();
});

/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 


this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



// starting the script on page load
$(document).ready(function(){
	tooltip();
});

// video overlay
$(document).ready(function(){
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.35, /* Value betwee 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'dark_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */
		modal: false, /* If set to true, only the close button will close the window */
		changepicturecallback: function(){}, /* Called everytime an item is shown/changed */
		callback: function(){} /* Called when prettyPhoto is closed */
	});
});

function PrintThisPage()
{
	var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,";
	sOption+="scrollbars=yes,width=750,height=550,left=100,top=25";
	var sWinHTML = document.getElementById('pcontent').innerHTML;
	var winprint=window.open("","",sOption);
	winprint.document.open();
	winprint.document.write('<html><link rel="stylesheet" type="text/css" href="/iseek/_ui/css/print.css" media="screen, print, projection, tv" /><body>');
	winprint.document.write(sWinHTML);
	winprint.document.write('</body></html>');
	winprint.document.close();
	winprint.focus();
} 


