﻿function openSlideView(queryString)
{
    OpenWindowFix( "/News/Photo/SlideView.aspx?"+queryString, "SlideView", "740", "670" ); // 656
}

function openPreviewAritcle(postSn)
{
    OpenWindowScroll( "/News/Admin/Article/PreviewArticle.aspx?pSn="+postSn, "previewArticle", "760", "600" );
}

var mLink;
var mWindow;
function openMovie(movieLink)
{
    if( movieLink == null || movieLink.length == 0 )
    {
        alert('동영상 링크를 입력해 주십시오.');
        return;
    }
        
    mWindow = window.open('PreviewMovie.aspx', 'PreviewMovie','toobar=0,scrollbars=1,menubar=0,resizable=1,width=' + 430 + ',height=' + 400 );
    mLink = movieLink;
    
    setTimeout('setMovieLink()', 500);
}

function setMovieLink()
{
    var ctl = mWindow.document.getElementById('divMovie');
    if( mWindow == null || ctl == null )
    {
        setTimeout('setMovieLink()', 500);
        return;
    }

    ctl.innerHTML = mLink;
    ctl.style.paddingTop = '5px';
    ctl.style.textAlign = 'center';
    mWindow.focus();
}



function getMovieTag(src, width, height)
{
	return getMovieTag(src, width, height, "", "true", "true", "false", "true", "1")
}

function getMovieTag(src, width, height, style, showControls, showStatusBar, showDisply, autoStart, playCount)
{
    var tag = "<object classid=\"clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=6,4,5,715\" standby=\"loading microsoft windows media player components...\" type=\"application/x-oleobject\" width=\""+width+"\" height=\""+height+"\" style=\""+style+"\"><param name=\"filename\" value=\""+src+"\" /><param name=\"showcontrols\" value=\""+showControls+"\" /><param name=\"showstatusbar\" value=\""+showStatusBar+"\" /><param name=\"showdisplay\" value=\""+showDisply+"\" /><param name=\"autostart\" value=\""+autoStart+"\" /><param name=\"playcount\" value=\""+playCount+"\" /><param name=\"enablecontextmenu\" value=\"true\" /><param name=\"transparentatstart\" value=\"true\" /><param name=\"animationatstart\" value=\"true\" /><param name=\"volume\" value=\"-600\" /></object>";
    return tag;
}


function showCommentDelete(showId, hideId)
{
    var showCtl = document.getElementById(showId);
    var hideCtl = document.getElementById(hideId);  
    
    if( showCtl != null )
        showCtl.style.display = 'block';
    
    if( hideCtl != null )
        hideCtl.style.display = 'none';
    
    return false;
}



function showPostDeletedBox()
{
    var ctlBox = document.getElementById("guestPostDelete");
    var ctlPwd = document.getElementById("ctl00_cpContent__tbxPostDelete");
    var ctl = document.getElementById("ctl00_cpContent__btnDelete");
    
    if( ctlPwd != null )
        ctlPwd.value = "";
    
    ctlBox.style.left = GetPositionLeft(ctl);
    ctlBox.style.top = GetPositionBottom(ctl) + 10;
    ctlBox.style.display = "block";
}


function hidePostDeletedBox()
{
    var ctlBox = document.getElementById("guestPostDelete");
    
    ctlBox.style.display = "none";
}


var slider = 
{
    /// 이전에 가리켰던 인덱스를 말한다.    
    prevIndex : -1, 
    
    /// 이전에 가리켰던 인덱스를 말한다.
    curIndex : -1,
    
    isAutoSlide : 0,
    
    slideSeconds : 3,
    
    imgControl : null,
    
    navControl : null,
    
    viewControl : null,
    
    timerControl : null,
    
    selectControl : null, 
    
    /// 슬라이더 아이템의 집합이다.
    items : [], 
    
    init : function(navId, viewId, imgId)
    {
        this.navControl = $(navId);
        this.viewControl = $(viewId);
        this.imgControl = $('imgSlide');
        
        AttachEvent(this.viewControl, "click", function(){ slider.nextItem(); }, false);
        this.viewControl.style.cursor = "pointer";
        
        
        var prevBtn = $('imgPrevBtn');
        var nextBtn = $('imgNextBtn');
        
        if(isIE)
	        prevBtn.style.filter = "alpha(opacity='10')";
	    else
		    prevBtn.style.opacity = 0.1;
		AttachEvent(prevBtn, "mouseover", function(){ if(isIE) prevBtn.style.filter = "alpha(opacity='80')"; else prevBtn.style.opacity = 0.8; }, false);
		AttachEvent(prevBtn, "mouseout", function(){ if(isIE) prevBtn.style.filter = "alpha(opacity='10')"; else prevBtn.style.opacity = 0.1; }, false);
		AttachEvent(prevBtn, "click", function(){ slider.prevItem(); }, false);
		prevBtn.style.cursor = "pointer";
		    
		if(isIE)
	        nextBtn.style.filter = "alpha(opacity='10')";
	    else
		    nextBtn.style.opacity = 0.1;
		    
		AttachEvent(nextBtn, "mouseover", function(){ if(isIE) nextBtn.style.filter = "alpha(opacity='80')"; else nextBtn.style.opacity = 0.8; }, false);
		AttachEvent(nextBtn, "mouseout", function(){ if(isIE) nextBtn.style.filter = "alpha(opacity='10')"; else nextBtn.style.opacity = 0.1; }, false);
        AttachEvent(nextBtn, "click", function(){ slider.nextItem(); }, false);
        nextBtn.style.cursor = "pointer";
    }, 
     
    getItem : function(index)
    {
        if( this.items == null && this.items.length <= index ) return null;
        return this.items[index];        
    }, 
    
    getItemCount : function()
    {
        if( this.items == null ) return 0;
        
        return this.items.length;
    },
    
    addItem : function(divId, attachUrl)
    {
        var idx = this.items.length;        
        this.items[idx] = {divControl:$(divId), url:attachUrl};
    }, 
        
    findIndex : function(item)
    {
        if( this.items == null || this.items.length == 0) return -1;
        
        for( var i=0 ; i < this.items.length ; ++i )
        {
            if( this.items[i].divControl.id == item.divControl.id )
                return i;
        }
        
        return -1;
    },
    
    setItem : function(index)
    {
        if( this.items == null || this.items.length ==0 || this.items.length <= index ) return null;
        if( this.timerControl != null ) this.stopAutoSlide();
        
        this.prevIndex = this.curIndex;
        this.curIndex = index;
        
        if( this.prevIndex > -1 )
            this.items[this.prevIndex].divControl.className = 'Normal';

        var curItem = this.items[this.curIndex];
        
       
        curItem.divControl.className = 'Selected';        
        this.viewControl.src = curItem.url;
        this.navControl.innerText = (this.findIndex(curItem)+1) + " / " + this.getItemCount();
    },
    
    prevItem : function()
    {
        var idx = this.curIndex -1;
        if( idx < 0 ) 
        { 
            if( this.items.length > 0 ) 
                idx = this.items.length-1;
            else 
                return;
        }
        
        this.setItem(idx);
    },
    
    nextItem : function()
    {
        var idx = this.curIndex + 1;        
        if( this.items.length <= idx ) idx = 0;               
        this.setItem(idx);
    },
    
    setAutoItem : function(index)
    {
        if( this.items == null || this.items.length <= index ) return null;
        
        this.prevIndex = this.curIndex;
        this.curIndex = index;
        
        if( this.prevIndex > -1 )
            this.items[this.prevIndex].divControl.className = 'Normal';

        var curItem = this.items[this.curIndex];
               
        curItem.divControl.className = 'Selected';        
        this.viewControl.src = curItem.url;
        this.navControl.innerText = (this.findIndex(curItem)+1) + " / " + this.getItemCount();
    },
    
    slideNext : function()
    {   
        var idx = this.curIndex + 1;        
        if( this.items.length <= idx ) idx = 0;               
        this.setAutoItem(idx);        
        
        this.timerControl = setTimeout("slider.slideNext();", this.slideSeconds*1000);        
    }, 
    
    startAutoSlide : function()
    {
        if( this.items == null || this.items.length == 0 ) return;
        
        this.stopAutoSlide();     
      
        this.slideSeconds = $F("ddlTime");
        this.slideNext();        
        
        
        this.isAutoSlide = 1;
    },
    
    toggleAutoSlide : function()
    {
        if( this.isAutoSlide == 1 )
        {   
            this.stopAutoSlide();
        }
        else
        {
            this.startAutoSlide();
            
            this.imgControl.src = '/Skin/Default/Photo/Images/Slide/02-1.gif';                
            this.imgControl.style.cursor = 'hand';
        }        
    },
    
    stopAutoSlide : function()
    {    
        if( slider.timerControl != null )
        {
            clearTimeout(slider.timerControl);
            slider.timerControl = null;
        }       
        
        this.imgControl.src = '/Skin/Default/Photo/Images/Slide/02.gif';
        this.imgControl.style.cursor = 'hand';
        
        this.isAutoSlide = 0;
    }
}


