jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", ( $(window).height() - this.height() ) * 0.5+$(window).scrollTop() + "px");
    this.css("left", ( $(window).width() - this.width() ) * 0.5+$(window).scrollLeft() + "px");
    return this;
}

function Toggleshow(selector)
{
    this.selector=selector;
    this.count=$(this.selector).size();
    this.current=0;
}
Toggleshow.prototype.shownext=function()
{
    if(this.current+1<this.count)
    {
        this.current++;
        $(this.selector).fadeOut(500);
        $(this.selector+':eq('+this.current+')').fadeIn(500);
    }
}
Toggleshow.prototype.showprevious=function()
{
    if(this.current>0)
    {
        this.current--;
        $(this.selector).fadeOut(500);
        $(this.selector+':eq('+this.current+')').fadeIn(500);
    }
}

$(document).ready(function(){
//show menu of products
    $('.psort').hover(function(){
        $(this).find('.productmenu').show();
    },function(){
        $(this).find('.productmenu').hide();
    });
//decide video button
    if($('#videowindow').css('display')!='block')
    {
        $('.docvideohandle #minimize').hide();
        $('.docvideohandle #maximize').show();
    }else
    {
        $('.docvideohandle #maximize').hide();
        $('.docvideohandle #minimize').show();
    }
//draggable video's window
    $(".docvideo").draggable({handle:".docvideohandle",scroll:false,stop:function(event,ui){
		var top=parseInt($(this).css('top'));
		var left=parseInt($(this).css('left'));
		$.cookie('videotop',top,{path:'/'});
		$.cookie('videoleft',left,{path:'/'});
	}});
//minimize video window
    $('.docvideohandle #minimize').click(function(){
        $('#videowindow').hide();
        $('#minimize').hide();
        $('#maximize').show();
        $.cookie('videodisplay','none',{path:'/'});
    });
//maximize video window    
    $('.docvideohandle #maximize').click(function(){
        $('#videowindow').show();
        $('#maximize').hide();
        $('#minimize').show();
        $.cookie('videodisplay','block',{path:'/'});
    });
//toggle display video window
    $('.docvideohandle').dblclick(function(){
        $('#videowindow').toggle();
        $('#minimize').toggle();
        $('#maximize').toggle();
        if($.cookie('videodisplay')=='block')
        {
            $.cookie('videodisplay','none',{path:'/'});
        }else
        {
            $.cookie('videodisplay','block',{path:'/'});
        }
    });



/*
//drag control panel;
	$('.cpanel').draggable({snap:true,containment:'document',scroll:false,stop:function(event,ui){
		var top=parseInt($(this).css('top'));
		var left=parseInt($(this).css('left'));
		var param='/'+top+'|'+left;
		$('.cpanellock').parent('a').attr('href','/index.php/welcome/lock'+param);
	}});
//Accordion cpanel
	var activeindex=$('.cpanel').attr('active');
	//var activeele=$('h3:eq('+activeindex+')');
	$('.rolepanel').accordion({active:'h3:eq('+activeindex+')'});
//close register/login/retrievepwd panel
	$('.closepanel').click(function(){
		$('.panel').hide();
		$('.screencover').hide();
	});
//login
  $('#login').click(function(){
    var screenheight=$('.screen').outerHeight();
	  $('.screencover').css({'height':screenheight,'opacity':0.7});
	  $('.flash').hide();
	  $('.screencover').show();
    $('.loginwindow').center();
    $('.loginwindow').show();
	});
//close login	
  $('.closewindow').click(function(){
    $('.loginwindow').hide();
    $('.screencover').hide();
    $('.flash').show();
  });
  */
});

