
//var dir = 'http://127.0.0.1/blogparts2/';
var dir = 'http://www.studiosearch.jp/';
var pfx0 = 'PhotoCalendar_';
document.write( '<script type="text/javascript" src="http://www.studiosearch.jp/js/jquery/jquery-1.4.2.min.js"></script>' );
//document.write( '<script type="text/javascript" src="js/jquery/' +dir+'jquery-1.4.2.min.js"></script>' );
// =========================================================================

PhotoCalendar = function(){
    var obj   = this;
    this.frame= '';
    this.pfx  = '';

    this.dog    = function(){ this.main('dog') }
    this.cat    = function(){ this.main('cat'  ) }
    this.season = function(){ this.main('season' ) }

    this.ldog    = function(){ this.main('dog','large') }
    this.lcat    = function(){ this.main('cat','large'  ) }
    this.lseason = function(){ this.main('season','large' ) }
    
    this.main = function( mode, size ){
       
       this.mode = mode;
       this.size  = (size)?size:'mini';
       
       this.pfx  = pfx0 + mode + '_'+ size + '_';
       this.frame= '#'+ this.pfx +'body';
       
       this.chara = this.data[mode];
       this.charaframe = this.data[mode].frame[this.size];
       this.addHeader();
       
       document.write( '<div id="'+ obj.pfx +'body"></div>' );
       this.makeView();
       
   };
   
   this.today = new Date();
   this.count = 0;
   
   this.data  = {
       dog :{
           frame   : {
               mini  : { 
                   frame  : { width : 160, height : 193 }, 
                   window : { width : 130, height : 109 , left: 15 , top: 18 }, 
                   date   : { top   : 147, style  : 'font-weight:bold; font-size:15px;' },
                   img    : dir+ 'img/frame/bp21.gif'
               },
               large  : { 
                   frame  : { width : 300, height : 322 }, 
                   window : { width : 246, height : 205 , left: 28 , top: 34 }, 
                   date   : { top   : 271, style  : 'font-weight:bold; font-size:18px;' },
                   img    : dir+ 'img/frame/bp22.gif'
               }
           },
           style   : 'color:#000000;',
           photosrc: function(){ return obj.daynumsrc() }
       },
       cat :{
           frame   : {
               mini  : { 
                   frame  : { width : 160, height : 187 }, 
                   window : { width : 127, height :  99 , left: 16 , top: 20 }, 
                   date   : { top   : 141, style  : 'font-weight:bold; font-size:15px;' },
                   img    : dir+ 'img/frame/bp31.gif'
               },
               large  : { 
                   frame  : { width : 300, height : 317 }, 
                   window : { width : 236, height : 186 , left: 31 , top: 39 }, 
                   date   : { top   : 260, style  : 'font-weight:bold; font-size:18px;' },
                   img    : dir+ 'img/frame/bp32.gif'
               }
           },
           style   : 'color:#000000;',
           photosrc: function(){ return obj.daynumsrc() }
       },
       season :{
           frame   : {
               mini  : { 
                   frame  : { width : 160, height : 231 }, 
                   window : { width : 134, height : 121 , left: 13 , top: 24 },
                   date   : { top   : 168, style  : 'font-weight:bold; font-size:15px;' },
                   img    : dir+ 'img/frame/bp11.gif'
               },
               large  : { 
                   frame  : { width : 300, height : 334 }, 
                   window : { width : 253, height : 229 , left: 23 , top: 26 }, 
                   date   : { top   : 283, style  : 'font-weight:bold; font-size:18px;' },
                   img    : dir+ 'img/frame/bp12.gif'
               }
           },
           style   : 'color:#000000;',
           photosrc: function(){ return obj.datesrc() }
       }
   };

   // =========================================================================
   // ヘッダー追加
   this.addHeader = function() {
       $('head').append( '<style>'+
         ' #'+ this.pfx +'body  { width :'+ obj.charaframe.frame.width +'px; }'+
         ' #'+ this.pfx +'body  { height:'+ obj.charaframe.frame.height +'px; }'+
         ' #'+ this.pfx +'body  { '+ obj.chara.style +' }'+
         ' #'+ this.pfx +'body *{ font-size:12px; font-weight:normal; margin:0; padding:0; text-align:left; }'+
         ' #'+ this.pfx +'body *{ background:none; border:none; }'+
         
         ' #'+ this.pfx +'back  { width:100%; height:100%; }'+
         
         ' #'+ this.pfx +'frame { width:100%; height:100%; }'+
         ' #'+ this.pfx +'frame { background:none no-repeat; }'+
         ' #'+ this.pfx +'frame { background-image:url('+ obj.charaframe.img +'); border:none;  }'+
         ' #'+ this.pfx +'frame { position:relative; }'+
         
         ' #'+ this.pfx +'img   { background:none; border:none; }'+
         ' #'+ this.pfx +'img   { width :'+ obj.charaframe.window.width +'px; }'+
         ' #'+ this.pfx +'img   { height:'+ obj.charaframe.window.height +'px; }'+
         
         ' #'+ this.pfx +'img   { position:absolute }'+
         ' #'+ this.pfx +'img   { left :'+ obj.charaframe.window.left +'px; }'+
         ' #'+ this.pfx +'img   { top  :'+ obj.charaframe.window.top  +'px; }'+
         
         ' #'+ this.pfx +'photo { cursor:pointer; }'+
         
         ' #'+ this.pfx +'date  { position:absolute; }'+
         ' #'+ this.pfx +'date  { width:100%; text-align:center; }'+
         ' #'+ this.pfx +'date  { '+ obj.charaframe.date.style  +' }'+
         ' #'+ this.pfx +'date  { top :'+ obj.charaframe.date.top  +'px; }'+
         
       '</style>');
   };
   
   // メイン画面作成
   this.makeView = function() {
       $( obj.frame ).empty();
       $( obj.frame ).append( '<div id="'+ obj.pfx +'head"></div>' );
       $( obj.frame ).append( obj.makeBody() );
       
       $( '#'+ this.pfx +'photo' )
           .attr('src'   , obj.chara.photosrc() )
           .attr('width' , obj.charaframe.window.width )
           .attr('height', obj.charaframe.window.height )
       
           //.live('click', function(){ obj.nextDay() } )  // for debug; click to next date
           .live('click', function(){ window.open( this.src, null ) } ) // click to show large image
       ;
   };
   
   // ブログパーツ作成
   this.makeBody = function() {
       var body = $('<div id="'+ this.pfx +'back">');
       
       $(body).append(
           '<div id="'+ this.pfx +'frame">' + 
           '<div id="'+ this.pfx +'img">'+
           '<img id="'+ this.pfx +'photo" src="#" alt="todays photo"/>'+
           '</div>'+
           '<div id="'+ this.pfx +'date">' + obj.formateddate() + '</div>'+
           '</div>'
       );
       
       return body;
   };
   
   // ファイル名作成　：カウント
   this.countsrc = function(){
       if( ++obj.count > 365 ){ obj.count=1; }
       var num = '000' + obj.count ;
       num     = String(num).slice(-3);
       
       return obj.adddir( num );
   };
   
   // ファイル名作成　：日数
   this.daynumsrc = function(){
       var first = new Date(obj.today.getTime() );
           first.setMonth(0); //January
           first.setDate(1);  //1st
       var today = new Date();
       today.setTime( obj.today.getTime() );
       var dif   = ( today.getTime()-first.getTime() ) / 1000 / 3600 / 24 +1;
       var num   = '000' + dif ;
       num       = String(num).slice(-3);
       
       return obj.adddir( num );
   };
   
   // ファイル名作成　：日付
   this.datesrc = function(){
       var today = new Date();
           today.setTime( obj.today.getTime() );
       var date  = String( '00' + (today.getMonth()+1) ).slice(-2) +
                   String( '00' + today.getDate() ).slice(-2)
       ;
       
       return obj.adddir( date );
   };
   
   // カレント移動
   this.nextDay = function(){
       
       obj.today.setTime( obj.today.getTime() + (1000*3600*24) );
       $( '#'+ this.pfx +'photo' ).attr( 'src', obj.chara.photosrc() );
       $( '#'+ this.pfx +'date'  ).html( obj.formateddate() );
       
   };
   
   this.adddir = function( file ){
       return dir+'img/'+obj.mode+'/'+ file +'.jpg';
   };
   
   this.formateddate = function(){
       var date  = String( '00' + (obj.today.getMonth()+1) ).slice(-2) + 
                   '/'+
                   String( '00' + obj.today.getDate() ).slice(-2)
       return date;
   };

}

