﻿$(function(){

    var photoNum = 6; //must be larger than 4
    
    //photo swap handler
    $('#s_photo>img').live('click',
        function(){
            var s = $(this).attr('src');
            s = s.replace('_s_','_');
            $('#photo>img').attr('src',s);
        }
    );
    
    //next btn click handler
    $('#next').click(
        function(){
            var i = getFirstImgIndex();
            for(j=0;j<4;j++){
                i++;
                if(i>photoNum)i=1;
                $('#s_photo img:eq('+j+')').attr('src','img/slider/photo_s_'+i+'.jpg');
            }
        }
    );
    //prev btn click handler
    $('#prev').click(
        function(){
            var i = getLastImgIndex();
            for(j=3;j>=0;j--){
                i--;
                if(i==0)i=photoNum;
                $('#s_photo img:eq('+j+')').attr('src','img/slider/photo_s_'+i+'.jpg');
            }
        }
    );
	
    //photo link click handler
	/***
	ex.
	(increase)
				case '1' :
					window.open('link','','menubar=no,status=no,scrollbars=no,top=0,left=0,toolbar=no,width=1000,height=600');
					$('#photo>img').css('cursorhand');
					break;
	**/
	/***
	(remove)
				case '1' :
					break;  
	
	**/
	
    $('#photo').click(
        function(){
			linkopen = $('#photo>img').attr('src').substr(17,1);
			switch(linkopen){
				case '1' :
					window.open('http://www.go2taiwan.net/eBook_05032011/book_swf.html','','menubar=no,status=no,scrollbars=no,top=0,left=0,toolbar=no,width=1000,height=600');
					$('#photo>img').css('cursorhand');
					break;
				case '2' :
					break;
				case '3' :
					
					break;
				case '4' :case '5' :case '6' :case '7' :case '8' :
					break;

			}
        }
    );
    
    function getFirstImgIndex(){
        var s = $('#s_photo>img:first-child').attr('src')
        var i = s.indexOf('.jpg')-1;
        s = s.charAt(i)
        return s;
    }
    
    function getLastImgIndex(){
        var s = $('#s_photo>img:last-child').attr('src')
        var i = s.indexOf('.jpg')-1;
        s = s.charAt(i)
        return s;
    }
});
