//
//  InstituteWebViewController.m
//  mTLU 2.0
//
//  Created by Developer on 4/25/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "InstituteWebViewController.h"


@implementation InstituteWebViewController

- (id)initWithURL:(NSString *) urlAddress

{
    self = [super init];
    if (self) {
        // Custom initialization
        webView=[[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 416)];
        [self.view addSubview: webView];
        webView.delegate=self;
        webView.scalesPageToFit=YES;
        // Do any additional setup after loading the view.
        NSURL *url = [NSURL URLWithString:urlAddress];
        //URL Requst Object
        NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
        //Load the request in the UIWebView.
        [webView loadRequest:requestObj];
        activity=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        [activity setCenter:webView.center];
        [self.view addSubview:[self getToolbar]];
    }
    return self;
}


-(UIToolbar *) getToolbar 
{
    UIToolbar *toolbar=[[UIToolbar alloc] initWithFrame:CGRectMake(0, 416, 320, 44)];
  //  toolbar.tintColor=[UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1];
    
    UIBarButtonItem *spaceOne=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    spaceOne.width=30;
    

    UIBarButtonItem *backButton=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"arrow_left.png"] style:UIBarButtonItemStylePlain target:webView action:@selector(goBack)];
   
    UIBarButtonItem *spaceTwo=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    spaceTwo.width=30;
    

    UIBarButtonItem *forwardButton=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"arrow_right.png"] style:UIBarButtonItemStylePlain target:webView action:@selector(goForward)];
    
    
    UIBarButtonItem *spaceThree=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    spaceThree.width=40;
    
    UIBarButtonItem *refreshButton=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:webView action:@selector(reload)];

    UIBarButtonItem *spaceFour=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    spaceFour.width=50;
    

    UIBarButtonItem *closeButton=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(closeController)];
    
    UIBarButtonItem *spaceFive=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    spaceFive.width=30;
    
    [toolbar setItems:[[NSArray alloc] initWithObjects: spaceOne, backButton,spaceTwo,forwardButton,spaceThree, refreshButton, spaceFour, closeButton, spaceFive,  nil]];
     return toolbar;
}
-(void) closeController {
    [self dismissModalViewControllerAnimated:YES];
}
-(void) webViewDidStartLoad:(UIWebView *)webV {
    [webView addSubview:activity];
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
    [activity startAnimating];
}
-(void) webViewDidFinishLoad:(UIWebView *)webV {
    [activity removeFromSuperview];
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
    [activity stopAnimating];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
