/*
 * AppController.j
 *
 * Created by __Me__ on __Date__.
 * Copyright 2008 __MyCompanyName__. All rights reserved.
 */

@import <Foundation/CPObject.j>


@implementation AppController : CPObject
{
	CPScrollView scrollView;
	CPImageView imageView;
	CPImage image1;
	CPImage image2;
	CPTimer timer;
}

- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
    var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
        contentView = [theWindow contentView];

	
	imageView = [[CPImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
	[imageView setHasShadow:NO];
	[imageView setImageScaling:CPScaleNone];

	var mainBundle = [CPBundle mainBundle];

	var path = [mainBundle pathForResource:@"PLL_0018_550_368.jpg"];
	image1 = [[CPImage alloc] initWithContentsOfFile:path size:CGSizeMake(550, 368)];
	
	var path = [mainBundle pathForResource:@"PLL_0033_550_368.jpg"];
	image2 = [[CPImage alloc] initWithContentsOfFile:path size:CGSizeMake(550, 368)];
	
	var imageSize = [image1 size];
	[imageView setFrameSize:imageSize];
	[imageView setImage:image1];
		
	scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth([contentView bounds]), CGRectGetHeight([contentView bounds]))];
	[scrollView setAutoresizingMask: CPViewWidthSizable | CPViewHeightSizable];
	[scrollView setAutohidesScrollers:YES];
	[scrollView setDocumentView:imageView];
			 
	[contentView addSubview:scrollView];

//	debugger;

	var objects = [[CPArray alloc] initWithObjects:[CPNumber numberWithLong:0], nil];
	var keys = [[CPArray alloc] initWithObjects:@"currentIndex", nil];
	var dict = [[CPDictionary alloc] initWithObjects:objects forKeys:keys];

	timer = [CPTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(switchImage:) userInfo:dict repeats:YES];

    [theWindow orderFront:self];
}

-(void)switchImage:(CPTimer)aTimer
{
//	debugger;
	
	var dict = [aTimer userInfo];
	var currentIndex = [[dict objectForKey:@"currentIndex"] longValue];

	if (currentIndex == 0)
	{
		[imageView setImage:image2];
		currentIndex = 1;
		[dict setObject:[CPNumber numberWithLong:currentIndex] forKey:@"currentIndex"];
	}
	else
	{
		[imageView setImage:image1];
		currentIndex = 0;
		[dict setObject:[CPNumber numberWithLong:currentIndex] forKey:@"currentIndex"];
	}
}

@end
