//obj
gd = {};
// class
gdc = {};
//define
gdd = {};

gdd.TMP = {
  ID:'tmp',
  UID:'#tmp',
  CHILD:'> .tmp',
  URLDEBUG: '../'
};


gdd.SYNC    = 'sync';
gdd.DATA    = 'json';
gdd.Angle   = 40;
gdd.VAR = {};
gdd.SVAR = {};
gdd.EVENT = {};


gd.Mgr = {};


gdd.DIVBK         = '<div></div>';
gdd.SPANBK         = '<span></span>';
gdd.LINK         = '<a></a>';
gdd.IMG        = '<img></img>';

gdd.TBK = '<table></table>';
gdd.TRBK = '<tr></tr>';
gdd.THBK = '<th></th>';
gdd.TDBK = '<td></td>';




function addGDItem(id, name, link){

// $(gdd.DIVBK)
//  .appendTo('#main')
//    .attr('id', 'bk'+id)
////    .addClass('blockicon')
//    //.corner()
//    ;

// $(gdd.LINK)
//  .appendTo('#block')
//    .attr('id', 'bk00')
//    .attr('target', '_new')
//    .attr('alt', 'Bubble Fans')
//    .attr('href', 'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=353430954&mt=8');

  var img = './img/gd'+id+'s.jpg';
  $(gdd.IMG)
    .attr('id', 'itemimg'+id)
//    .appendTo('#block')
    .addClass('itemicon')
  //  .attr('border', 0)
    .css('opacity', 0)
    .css('width', 64)
    .css('height', 64)
    .attr('src', img)

    .wrap(gdd.SPANBK)
    .parent()
    .attr('id', 'item'+id)
    .css( 'background', 'url('+img+') no-repeat scroll center center transparent')
    .css('width', 180)
    .css('height', 180)
//    .css('width', $('#itemimg'+id).width())
//    .css('height', $('#itemimg'+id).height())
    .addClass('itemicon') 
    .wrap(gdd.LINK)
    .parent()
    .attr('target', '_new')
    .attr('alt', name)
    .attr('href', link)
    .wrap(gdd.DIVBK)
    .parent()
    .attr('id', 'bk'+id)
    .addClass('block')
    .appendTo('#main')
    ;


//    .parent()
//    .corner(0);

//<span style="background: url(&quot;./img/gd00s.jpg&quot;) no-repeat scroll center center transparent; \n\
//width: 180px; height: 90px;" class="itemicon"><img id="itemimg00" class="itemicon" src="./img/gd00s.jpg" style="opacity: 0;"></span>


}


function iphoneInit(){
  $(gdd.DIVBK)
  .appendTo('body')
    .attr('id', 'header');
  $(gdd.DIVBK)
  .appendTo('body')
    .attr('id', 'title');

  $('<img/>')
  .appendTo('#header')
    .attr('id', 'titlelogo')
    .attr('src', './img/logo_24.png');

  $('<img/>')
  .appendTo('body')
    .attr('id', 'bglogo')
    .attr('src', './img/logo_400_bg.png');
  $(gdd.SPANBK)
  .appendTo('#title')
    .attr('id', 'title1')
    .html('funny');
  $(gdd.SPANBK)
  .appendTo('#title')
    .attr('id', 'title1dot')
    .html('. ');
  $(gdd.SPANBK)
  .appendTo('#title')
    .attr('id', 'title2')
    .html('handy');
   $(gdd.SPANBK)
  .appendTo('#title')
    .attr('id', 'title2dot')
    .html('. ');
  $(gdd.SPANBK)
  .appendTo('#title')
    .attr('id', 'title3')
    .html('kindly');



// contain
 $(gdd.DIVBK)
  .prependTo('body')
    .attr('id', 'main');

  addGDItem('02',
            'The Dark Age',
            'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=408128359&mt=8');
  addGDItem('01',
            'Bubble Fans - Save me from the Piggy Bank',
            'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=379474362&mt=8');
  addGDItem('00',
            'Bubble Fans',
            'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=353430954&mt=8');


    $('.itemicon')
    .corner();

//news

  /*
    $('#news')
    .append(new TWTR.Widget({
        version: 2,
        type: 'profile',
        rpp: 4,
        interval: 6000,
        width: 180,
        height: 250,
        theme: {
          shell: {
            background: '#d7ebd1',
            color: '#275527'
          },
          tweets: {
            background: '#fbeddd',
            color: '#687366',
            links: '#648a5f'
          }
        },
        features: {
          scrollbar: false,
          loop: false,
          live: false,
          hashtags: true,
          timestamp: true,
          avatars: false,
          behavior: 'all'
        }
        }).render().setUser('greenerydigital').start());
    */

//email
 $(gdd.DIVBK)
  .appendTo('body')
    .attr('id', 'footer');

 $(gdd.LINK)
  .appendTo('#footer')
    .attr('id', 'em')
   .attr('alt', 'Greenery')
    .attr('href', 'mailto:support@greenerydigital.com')
    .wrap('<div/>');


    
  $(gdd.IMG)
    .attr('id', 'emimg')
    .appendTo('#em')
  //  .attr('border', 0)
    .attr('src', './img/em.gif');
    



   
 //   $('')
    
  //  $('<a href="http://twitter.com/share" class="twitter-share-button" data-count="none">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>')
  //  .appendTo('#footer');
    
 $('#footer')
  .append('(c) 2009-2010 Greenery Digital Limited. All Rights Reserved.');


//if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
//{
//
//     $("#header").css("position", "static");
//
//};


//  $(".itemicon").load(function() {
//    $(this).wrap(function(){
////      return '<span class="' + $(this).attr('class') + '" style="background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />';
//      return '<span class="' + $(this).attr('class') + '" style="background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + 180 + 'px; height: ' + 90 + 'px;" />';
//    });
//    $(this).css("opacity","0");
//  });


//$('#title1').html(gdd.Angle);
//$('#titlelogo').rotate(0);
//$('#title1').rotate(0);

//$('#titlelogo')
//  .everyTime(1000, 'tlogo', function(){
//      gdd.Angle = gdd.Angle * -1;
//      $('#titlelogo').rotateAnimation(gdd.Angle);
//      $('#title1').rotateAnimation(gdd.Angle);
//      $('#title1').html(gdd.Angle);
//    });

	//$('#titlelogo').rotate({maxAngle:25,minAngle:-55

//$('#title2').animate({
//    rotate: 45 //rotates 45 degrees
//});
//$('#title2')
//  .animate(
//    {rotate: 80},
//    {
//      duration:1000,
//      easing:'easeInOutSine',
//      step:function()
//      {
//     //   console.log(this.rotate);
//      }
//    }
//  );
}



function webInit(){
  $(gdd.DIVBK)
  .appendTo('body')
    .attr('id', 'header');
  $(gdd.DIVBK)
  .appendTo('body')
    .attr('id', 'title');

//  $('<img/>')
//  .appendTo('#header')
//    .attr('id', 'titlelogo')
//    .attr('src', './img/logo_24.png');

  $('<img/>')
  .appendTo('body')
    .attr('id', 'bglogo')
    .attr('src', './img/logo_400_bg.png');
  $(gdd.SPANBK)
  .appendTo('#title')
    .attr('id', 'title1')
    .html('funny');
  $(gdd.SPANBK)
  .appendTo('#title')
    .attr('id', 'title1dot')
    .html('. ');
  $(gdd.SPANBK)
  .appendTo('#title')
    .attr('id', 'title2')
    .html('handy');
   $(gdd.SPANBK)
  .appendTo('#title')
    .attr('id', 'title2dot')
    .html('. ');
  $(gdd.SPANBK)
  .appendTo('#title')
    .attr('id', 'title3')
    .html('kindly');

// contain
 $(gdd.DIVBK)
  .prependTo('body')
    .attr('id', 'main');

  addGDItem('02',
            'The Dark Age',
            'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=408128359&mt=8');
  addGDItem('01',
            'Bubble Fans - Save me from the Piggy Bank',
            'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=379474362&mt=8');
  addGDItem('00',
            'Bubble Fans',
            'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=353430954&mt=8');



// news
//<script src="http://widgets.twimg.com/j/2/widget.js"></script>

    
$('#news')
  .appendTo('#footer');


//email
 $(gdd.DIVBK)
  .appendTo('body')
    .attr('id', 'footer');

 $(gdd.LINK)
  .appendTo('#footer')
    .attr('id', 'em')
   .attr('alt', 'Greenery')
    .attr('href', 'mailto:support@greenerydigital.com')
    .wrap('<div/>');


  $(gdd.IMG)
    .attr('id', 'emimg')
    .appendTo('#em')
  //  .attr('border', 0)
    .attr('src', './img/em.gif');

 $('#footer')
  .append('(c) 2009-2010 Greenery Digital Limited. All Rights Reserved.');



}
if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
  {
    $("#maincss").attr("href", "css/mobile.css");
  }
  
jQuery(document).ready(function($){

  //width = parseInt(width);
    
//    $(window).resize(function() {
      //adjustStyle();

  if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod')
  {
    $("#maincss").attr("href", "css/mobile.css");
     iphoneInit();

  }else
  {
          webInit();
  }
  //  });

 

});


