/* Start ----------------------------------------------------- strings.js*/

// ==========================================================================
// TechAlley English Strings
// ==========================================================================

// Place strings you want to localize here.  In your app, use the key and
// localize it using "key string".loc().  HINT: For your key names, use the
// english string with an underscore in front.  This way you can still see
// how your UI will look and you'll notice right away when something needs a
// localized string added to this file!
//
Object.extend(String.English,{
  // "_String Key": "Localized String"
}) ;


/* End ------------------------------------------------------- strings.js*/

/* Start ----------------------------------------------------- core.js*/

// ==========================================================================
// TechAlley
// ==========================================================================

TechAlley = SC.Object.create({

  // This will create the server for your application.  Add any namespaces
  // your model objects are defined in to the prefix array.
  server: SC.Server.create({ prefix: ['TechAlley'] }),

  // When you are in development mode, this array will be populated with
  // any fixtures you create for testing and loaded automatically in your
  // main method.  When in production, this will be an empty array.
  FIXTURES: []

}) ;


/* End ------------------------------------------------------- core.js*/

/* Start ----------------------------------------------------- main.js*/

// ==========================================================================
// TechAlley
// ==========================================================================

// This is the function that will start your app running.  The default
// implementation will load any fixtures you have created then instantiate
// your controllers and awake the elements on your page.
//
// As you develop your application you will probably want to override this.
// See comments for some pointers on what to do next.
//
function main() {

  //TechAlley.server.preload(TechAlley.FIXTURES) ;
  //TechAlley.awakeApp();
  //set grid to scroll horizontally
  //SC.page.getPath('main.gridScrollView').toggleProperty('canScrollHorizontal');
  
  //dev:	
  //TechAlley.loadThumbnails();
  
  //production:
  //TechAlley.server.request(TechAlley.VideoThumbnail.resourceURL(), 'video_thumbnail.php', null, {onSuccess: TechAlley.dataLoaded});
  new Ajax.Request('/data/video_thumbnail.php', { method:'get',
	  onSuccess: function(transport, json){
		if (transport.responseJSON && transport.responseJSON.records)
		{
			for (i=0; i<transport.responseJSON.records.length; i++)
			{
				record = transport.responseJSON.records[i];
			    SC.Store.addRecord( TechAlley.VideoThumbnail.create(
			    { 
			    	'url': record.url,
			    	'link': record.link 
			    }
			    ) );
			}
		}
		else
		{
			//alert("No video thumbnail data.");
		}
  		TechAlley.awakeApp();
	}
  });
  
  //var records = SC.Store.records();
  //var records = TechAlley.VideoThumbnail.collection() ;
  //records.refresh();
  //TechAlley.server.refreshRecords(records);

} ;

/*
TechAlley.dataLoaded = function(status, transport, cacheCode, context) 
{
	//alert('TechAlley.dataLoaded('+status+', '+transport+', '+cacheCode+', '+context+') ');
	if (transport.responseJSON && transport.responseJSON.records)
	{
		for (i=0; i<transport.responseJSON.records.length; i++)
		{
			record = transport.responseJSON.records[i];
		    SC.Store.addRecord( TechAlley.VideoThumbnail.create(
		    { 
		    	'url': record.url,
		    	'link': record.link 
		    }
		    ) );
		}
	}
  TechAlley.awakeApp();
}
*/

TechAlley.loadThumbnails = function() {
    SC.Store.addRecord( TechAlley.VideoThumbnail.create(
    { 
    	'url': 'http://techalley.cirne.com/images/Aging%202008%20-%20How%20Fast%20Will%20Stem%20Cell%20Research%20Advance.jpg',
    	'link': 'http://techalley.cirne.com/2008/07/09/aging-2008-panel-qa-how-fast-will-stem-cell-research-adavance/' 
    }
    ) );
    SC.Store.addRecord( TechAlley.VideoThumbnail.create(
    { 
    	'url': 'http://techalley.cirne.com/images/michael west announces embroyome.jpg',
    	'link': 'http://techalley.cirne.com/2008/07/07/michael-west-announces-embryomecom/' 
    }
    ) );
    SC.Store.addRecord( TechAlley.VideoThumbnail.create(
    { 
    	'url': 'http://techalley.cirne.com/images/Aging2008Walkthrough.jpg',
    	'link': 'http://techalley.cirne.com/2008/07/05/leading-up-to-aging-2008/' 
    }
    ) );
    SC.Store.addRecord( TechAlley.VideoThumbnail.create(
    { 
    	'url': 'http://techalley.cirne.com/images/%20Ars%20Technica%20&%20Gizmodo%20WWDC%20Party.jpg',
    	'link': 'http://techalley.cirne.com/2008/06/15/ars-technica-gizmodo-wwdc-party/' 
    }
    ) );
    SC.Store.addRecord( TechAlley.VideoThumbnail.create(
    { 
    	'url': 'http://techalley.cirne.com/images/iPhoneDevCampWalkthrough.jpg',
    	'link': 'http://techalley.cirne.com/2007/07/07/iphonedevcamp-walkthrough/' 
    }
    ) );
    SC.Store.addRecord( TechAlley.VideoThumbnail.create(
    { 
    	'url': 'http://techalley.cirne.com/images/JPG%20Party.jpg',
    	'link': 'http://techalley.cirne.com/2007/04/30/jpg-magazine-party/' 
    }
    ) );
    SC.Store.addRecord( TechAlley.VideoThumbnail.create(
    { 
    	'url': 'http://techalley.cirne.com/images/SHDH0b10000.jpg',
    	'link': 'http://techalley.cirne.com/2007/03/25/supperhappydevhouse-0b10000/' 
    }
    ) );
    SC.Store.addRecord( TechAlley.VideoThumbnail.create(
    { 
    	'url': 'http://techalley.cirne.com/images/Circling%20The%20iPhone.jpg',
    	'link': 'http://techalley.cirne.com/2007/01/10/circling-the-iphone/' 
    }
    ) );
    SC.Store.addRecord( TechAlley.VideoThumbnail.create(
    { 
    	'url': 'http://cirne.com/vlog/images/NewYearNewMediaPartI.jpg',
    	'link': 'http://techalley.cirne.com/2007/01/02/new-year-new-media-part-ii-of-ii/' 
    }
    ) );
    TechAlley.awakeApp();
}


TechAlley.awakeApp = function() {
    SC.page.awake() ;

    var thumbnails = TechAlley.VideoThumbnail.findAll();
    if (TechAlley.masterController)
    {
    	TechAlley.masterController.set('content',thumbnails);
	}
	
    SC.page.get('main'); 
}

/* End ------------------------------------------------------- main.js*/

/* Start ----------------------------------------------------- controllers/app.js*/

// ==========================================================================
// TechAlley.AppController
// ==========================================================================

require('core');

/** @class

  (Document Your View Here)

  @extends SC.Object
  @author AuthorName
  @version 0.1
  @static
*/
TechAlley.appController = SC.Object.create(
/** @scope TechAlley.appController */ {

  // TODO: Add your own code here.
  title: "Tech Alley"

}) ;


/* End ------------------------------------------------------- controllers/app.js*/

/* Start ----------------------------------------------------- controllers/master.js*/

// ==========================================================================
// TechAlley.MasterController
// ==========================================================================

require('core');

TechAlley.masterController = SC.ArrayController.create(
/** @scope TechAlley.masterController */ {
  allowsEmptySelection: false,
  allowsMultipleSelection: false,
  disclosureChanged: true,
  
  selectionObserver: function(calledFrom, objObserved, theObj)
  {
   	selection = this.get('selection');
   	link = selection[0].link;
   	if (link)
   	{
   		techAlleyBlog = document.getElementById("ifrmTechAlleyBlog");
   		if (techAlleyBlog)
   		{
  			SC.page.main.get("gridScrollView").transitionTo(3.0, "height: 2px;");
   			SC.page.get("gridDisclosure").triggerAction(SC.TOGGLE_BEHAVIOR);
   			techAlleyBlogPos = new Animator().addSubject(
   				new NumericalStyleSubject(techAlleyBlog, 'top', techAlleyBlog.style.top, "-97px"
   			));
   			techAlleyBlogPos.play();
  			//techAlleyBlog.style.top = "-79px";
   			techAlleyBlog.src = link;
   			setTimeout('resize_iframe()', 400);
 
   		}
   	}
   	
  }.observes('selection'),
  
  disclosureClicked: function()
  {
	techAlleyBlog = document.getElementById("ifrmTechAlleyBlog");
  	if (this.disclosureChanged)
  	{
		SC.page.main.get("gridScrollView").transitionTo(3.0, "height: 114px;");
		techAlleyBlogPos = new Animator().addSubject(
			new NumericalStyleSubject(techAlleyBlog, 'top', techAlleyBlog.style.top, "16px"
		));
		//techAlleyBlog.style.top = "34px";
  	}
  	else 
  	{
		SC.page.main.get("gridScrollView").transitionTo(3.0, "height: 2px;");
		techAlleyBlogPos = new Animator().addSubject(
			new NumericalStyleSubject(techAlleyBlog, 'top', techAlleyBlog.style.top, "-97px"
		));
		//techAlleyBlog.style.top = "-79px";
  	}
	techAlleyBlogPos.play();
	setTimeout('resize_iframe()', 400);
  }.observes('disclosureChanged')
  
}) ;

function resize_iframe()
{

	var height=window.innerWidth;//Firefox
	if (document.body.clientHeight)
	{
		height=document.body.clientHeight;//IE
	}
	//resize the iframe according to the size of the
	//window (all these should be on the same line)
	document.getElementById("ifrmTechAlleyBlog").style.height=parseInt(height-
	document.getElementById("ifrmTechAlleyBlog").offsetTop-8)+"px";
}

// this will resize the iframe every
// time you change the size of the window.
window.onresize=resize_iframe; 


/* End ------------------------------------------------------- controllers/master.js*/

/* Start ----------------------------------------------------- models/video_thumbnail.js*/

// ==========================================================================
// TechAlley.VideoThumbnail
// ==========================================================================

require('core');

/** @class

  (Document your class here)

  @extends SC.Record
  @author AuthorName
  @version 0.1
*/
TechAlley.VideoThumbnail = SC.Record.extend(
/** @scope TechAlley.VideoThumbnail.prototype */ {

  // TODO: Add your own code here.
  dataSource: TechAlley.server, 
  properties: ['url','link'],
  resourceURL: 'data'

 

}) ;


/* End ------------------------------------------------------- models/video_thumbnail.js*/

