//
// $Id: BoatDetails.js,v 1.1.1.1 2010/02/26 08:30:04 steve Exp $
//
var BoatDetails = function() {

    this.images    = new Array()

    this.contactUs = new ContactUs()
    this.lightbox  = new LightBoxGeneric()
    this.thickbox  = new ThickBoxGeneric()
    this.url       = new Url()

    this.init = function() {
    
        var self = this
        
        self.thickbox.init()

        self.id   = self.url.clickedUrlArg('Id')
        
        self.loadBoatDetails()
    }
    
    this.loadBoatDetails = function() {

        var self = this

        $.ajax({
                  type:     'POST',
                  url:      AJAXURL,
                  data:     'Action=getBoatDetails&Id=' + self.id,
                  dataType: 'json',
                  timeout:  40000,
            error:
                function() {
                    return false;
                },
            success:
                function(data) {
                    if (data.Error) {
                        alert(data.Message)
                    } else {

                        $('#boatDetailsTitle').html(data.Boat.model)

                        self.logo         = data.Boat.logo
                        self.description  = data.Boat.description
                        self.spec         = data.Boat.spec
                        self.dateAdded    = data.Boat.dateadded
                        self.model        = data.Boat.model
                        self.year         = data.Boat.year
                        self.ywno         = data.Boat.ywno
                        self.price        = data.Boat.price
                        self.location     = data.Boat.location
                        self.postcode     = data.Boat.locationpostcode
                        self.manufacturer = data.Boat.manufacturername
                        self.category     = data.Boat.category
                        self.engineType   = data.Boat.enginetype
                        self.images       = data.Boat.images

                        if (self.logo) {
                            self.showLogo(self.logo)
                        }
                        $('#boatDetailsDescription').html('<p>' + self.description + '</p>')
                        
                        if (self.spec) {
                            $('#boatSpecLink a').attr('href', self.spec)
                            $('#boatSpecLink').show()
                        }

                        $('#boatDetailsPrice').html(self.price)
                        $('#boatDetailsCategory').html(self.category)
                        $('#boatDetailsManufacturer').html(self.manufacturer)
                        $('#boatDetailsModel').html(self.model)
                        $('#boatDetailsYear').html(self.year)
                        $('#boatDetailsEnginetype').html(self.engineType)
                        $('#boatDetailsYwno').html(self.ywno)
                        $('#boatDetailsLocation').html(self.location + ', ' + self.postcode)

                        if (self.images) {
                            var len = self.images.length
                            var str = "<ul id='carousel' class='jcarousel-skin-tango'>"
                            for (var i = 0; i < len; i++) {
                                str = str
                                    + "<li><img src='" + self.images[i] + "' height='70'></li>"
                            }
                            str = str + '</ul>'
                        }
                        $('#boatDetailsImages').append(str)
                        $('#boatDetailsImages img').click( function() { self.highlightImage($(this)) })
                        $('#getMoreDetailsButton').click( function() { self.showMoreDetails() })
                        $('#moreDetailsSubmit').click( function() { self.contactUs.submitContactUs('Brokerage', self.id) })
                        $('#moreDetailsCancel').click( function() { self.hideMoreDetails() })

                        self.showTable()
                    }
                }
        })
    }
    
    this.showTable = function() {

        $('#boatDetailsDiv').fadeIn()

        $('#carousel').jcarousel({ visible:2, scroll:1, wrap:'both' })
        $('.jcarousel-skin-tango .jcarousel-clip-horizontal').css('width', '365px')
        $('.jcarousel-skin-tango .jcarousel-container-horizontal').css('width', '365px')
    }
    
    this.showLogo = function(logo) {
    
        var self = this
        
        $('#boatDetailsLogo').attr('src', logo.file)
        $('#boatDetailsLogo').attr('alt', logo.file)
        $('#boatDetailsLogo').show()
    }
    
    this.highlightImage = function(elem) {
    
        var self = this
        
        var src = $(elem).attr('src')

        $('#boatImageHighlightImage').attr('src', src)
        $('#boatImageHighlightImage').attr('alt', self.name)
        $('#boatImageHighlightImage').attr('title', self.name)
        
        
        $('#boatImageHighlightImage').click( function() { self.unHighlightImage() })
        $('#boatImageHighlightImageButton').click( function() { self.unHighlightImage() })

        $('#boatDetailsDiv').hide()
        $('#boatImageHighlight').fadeIn()
    }
    
    this.unHighlightImage = function() {
    
        $('#boatImageHighlight').hide()
        $('#boatDetailsDiv').fadeIn()
    }

    this.showMoreDetails = function() {

        $('#boatDetailsDiv').hide()
        $('#boatDetailsContact').fadeIn()
    }    

    this.hideMoreDetails = function() {

        $('#boatDetailsContact').hide()
        $('#boatDetailsDiv').fadeIn()
    }
}
