function productDetail(pars){
	
	var that=this;
	if(typeof(pars)!=="object" && (typeof(pars)==='string' || typeof(pars)==='number')){
		this.product_id = pars;
	}
	else{
		if(pars.id !=="undefined"){
			this.product_id = pars.id;
		}
		if(pars.ss_products_id !=='undefined'){
			this.ss_products_id = pars.ss_products_id;
		}
	}
	this.baseUrl="";
	this.getMB = new getMatBottom();
	this.vehicle_id = 0;
	this.method = '';
    if(typeof(that.ss_products_id) != "undefined"){
		this.uri = 'store_id/'+that.ss_products_id;
	} else if(typeof(that.product_id) != "undefined") {
		this.uri = 'product_id/'+that.product_id;
	} else return ErrorMessage('No product id was specified');
	
    
	this.getProductDetail = function(){
		if (!$("#results_box").length)
		{
			$("#update_box").attr('id', 'results_box');
		};		
        $("#results_box").html('<div id="results_white"></div>');
		$.ajax({
            url: that.baseUrl+'/ajax/product/get-product-detail/'+that.uri,
            type:'GET',
            dataType:'html',
            success : function(data) {
                $("#results_white").html(data);
                //$("#results_white").prepend('<div id="loader_box"></div>');
                $('#results_white > div.buttons').append('<table><tr class="vehicle-select"></tr><tr class="buttons"></tr></table>');
                that.setVehicleMenu();
                $('tr.buttons').append('<td valign="top" align="left"><div class="domtab" style="width: 565px; padding-top: 20px;"><ul class="domtabs"></ul></div></tr>');
                $('ul.domtabs').html('<li class="button" id="getVehicleCoverage"><a href="#">CAR COVERAGE</a></li><li id="getFeatureCoverage" class="button"><a href="#">FEATURES</a></li><li id="getFirmwareCoverage" class="button"><a href="#">FIRMWARE</a></li><li id="getInstallGuides" class="button"><a href="#">INSTALL GUIDES</a></li>');
               
                $('li.button').click(
                		function(){
                				if(typeof(that[$(this).attr('id')])=='function'){
                					that[$(this).attr('id')]();
                				}
                				return false;
                			}
                		);
                that.getVehicleCoverage();
            },
            
            error : function(xhr) {
            	ErrorMessage(xhr);
            }
        });
	};
	
	this.getVehicleCoverage = function(){
		$("#results_white > div.additional_detail").empty();
		showLoader();
		$("#results_white > div.additional_detail").html('<table class="vehicle-list" width="100%" cellspacing="0" cellpadding="0" border="0" ></table>');
		$("#results_white > div.additional_detail > table.vehicle-list").html('<tr><td class="product_name"  colspan="<?=count($this->years)/2?>"></td></tr>');
		$.ajax(
				{	url:that.baseUrl+'/ajax/product/get-vehicle-make-coverage/'+that.uri,
					data:{},
					type:'GET',
					dataType:'html',
					success : function(data){
						hideLoader();
						$("#results_white > div.additional_detail td.product_name").html("Current coverage for product: "+$("div.product_txt").html());
						$("#results_white > div.additional_detail td.product_name").after(data);
						$(".vehicleName > select").bind('change', function(){
							if($(this).val()!=0)
								that.getVehicleCoverageDetail($(this).val());
							
						});
						$(".vehicleName > select").after('<a class="all-makes">See complete coverage</a>');
						$(".vehicleName a.all-makes").click(
								function(){
									that.getVehicleCoverageDetail("all-makes");
								});
						$("td.vehicleName > select").attr('selectedIndex',1);
						$("td.vehicleName > select").change();
						
						
					},
	                error : function(xhr) {
	                	ErrorMessage(xhr);
					}
			});
		showLoader();
		that.method = '';
	};
	this.getVehicleCoverageDetail = function(id){
		$("div.additional_detail > table.vehicle-coverage").empty();
		showLoader();
		$.ajax(
				{	url:that.baseUrl+'/ajax/product/get-vehicle-coverage/'+that.uri+(id!="all-makes"?"/vehicleMake_id/"+id:""),
					data:{},
					type:'GET',
					dataType:'html',
					success : function(data){
						hideLoader();
						$('#results_white > div.additional_detail table.vehicle-coverage').remove();
						
						$("#results_white > div.additional_detail table.vehicle-list").after(''+data+'');
						$('#results_white tr').each(function(){$(this).children('td.table_bull:even, td.table_year:even').addClass('odd');})
	                    $('.button_on').addClass('button');
	                    $('li.button').removeClass('button_on');
	                    $('#getVehicleCoverage').addClass('button_on');
	                    $('#getVehicleCoverage').removeClass('button');
	                    that.getMB.getFeatureMatBottom();
					},
	                error : function(xhr) {
	                	ErrorMessage(xhr);
					}
			});
		that.method = '';
	};
	
	this.getFeatureCoverage = function(){
		$("#results_white > div.additional_detail").empty();
		showLoader();
		$.ajax(
				{	url: that.baseUrl+'/ajax/product/get-feature-coverage/'+that.uri+(that.vehicle_id != 0 ? '/vehicle_id/'+that.vehicle_id : ''),
					data:{},
					type:'GET',
					dataType:'html',
					success : function(data){
						hideLoader();
						$("#results_white > div.additional_detail").html(data);
						$("#results_white > div.additional_detail td.product_name").html("Available feature for the product: "+$("div.product_txt").html());
                        $('.button_on').addClass('button');
                        $('li.button').removeClass('button_on');
                        $('#getFeatureCoverage').addClass('button_on');
                        $('#getFeatureCoverage').removeClass('button');
					},
	                error : function(xhr) {
	                	ErrorMessage(xhr);
					}
				});
		that.method = 'getFeatureCoverage';
	};
	this.getFirmwareCoverage = function(){
		$("#results_white > div.additional_detail").empty();
		showLoader();
		$.ajax(
				{	url:that.baseUrl+'/ajax/product/get-firmware-coverage/'+that.uri+(that.vehicle_id != 0 ? '/vehicle_id/'+that.vehicle_id : ''),
					data:{},
					type:'GET',
					dataType:'html',
					success : function(data){
						hideLoader();
						$("#results_white > div.additional_detail").html(data);
						$("#results_white > div.additional_detail td.product_name").html("Available firmware for the product: "+$("div.product_txt").html());
                        $('.button_on').addClass('button');
                        $('li.button').removeClass('button_on');
                        $('#getFirmwareCoverage').addClass('button_on');
                        $('#getFirmwareCoverage').removeClass('button');
                        that.getMB.getFirmwareMatBottom();
					},
	                error : function(xhr) {
	                	ErrorMessage(xhr);
					}
				});
		that.method = 'getFirmwareCoverage';
	};
	
	this.getInstallGuides = function(){
		$("#results_white > div.additional_detail").empty();
		showLoader();
		$.ajax(
				{	url:that.baseUrl+'/ajax/product/get-install-guides/'+that.uri+(that.vehicle_id != 0 ? '/vehicle_id/'+that.vehicle_id : ''),
					data:{},
					type:'GET',
					dataType:'html',
					success : function(data){
                        hideLoader();
                        $("#results_white > div.additional_detail").html(data);
						$("#results_white > div.additional_detail td.product_name").html("Available install guides for the product: "+$("div.product_txt").html());
                        $('.button_on').addClass('button');
                        $('li.button').removeClass('button_on');
                        $('#getInstallGuides').addClass('button_on');
                        $('#getInstallGuides').removeClass('button');
					},
	                error : function(xhr) {
	                	ErrorMessage(xhr);
					}
				});
		that.method = 'getInstallGuides';
	};
	
	this.setVehicleMenu = function(){
		$('tr.vehicle-select').empty().append('<td></td>');
		$('tr.vehicle-select td').append('<select class="product-vehicle-make" name="product-vehicle-make"><option value="0">Select a make</option></select>');
		
        $('tr.vehicle-select td').append('<select class="product-vehicle-year" name="product-vehicle-year" disabled="disabled"><option value="0">Select a Year</option></select>');
        $('tr.vehicle-select td').append('<select class="product-vehicle-model" name="product-vehicle-model" disabled="disabled"><option value="0">Select a Model</option></select>');
        
        function buildMakes ()
        {
            $.ajax(
                    {   url:'/ajax/search/get-make-list/lan/En/'+that.uri,
                        data:{},
                        type:'GET',
                        dataType:'json',
                        success : function(data) {
                            $('tr.vehicle-select td > .product-vehicle-make').empty().append(createOption('','Select Make'));
                            for(x in data) {
                                $('tr.vehicle-select td > .product-vehicle-make').append(createOption(data[x]['id'],data[x]['vehicleMake']));
                            }
                            $('tr.vehicle-select td > .product-vehicle-year').attr('disabled','disabled');
                            $('tr.vehicle-select td > .product-vehicle-model').attr('disabled','disabled');
                        },
                        error : function(xhr) {
                        	ErrorMessage(xhr);
                        }
                    });
					
        }

        /**
         * When a make selection happens...
         */
        function makeSelection()
        {
            $('tr.vehicle-select td > .product-vehicle-make').bind('change', function() {
                $.ajax(
                        {   url:'/ajax/search/get-year-list/lan/En/'+that.uri,

                            data:{make:$(this).val()},
                            type:'GET',
                            dataType:'json',
                            success : function(data) {
                                $('tr.vehicle-select td > .product-vehicle-year').empty().append(createOption('','Select Year'));
                                for(x in data) {
                                    $('tr.vehicle-select td > .product-vehicle-year').append(createOption(data[x]['id'],data[x]['vehicleYear']));
                                }
                                $('tr.vehicle-select td > .product-vehicle-year').removeAttr('disabled');
                                $('tr.vehicle-select td > .product-vehicle-model').attr('disabled','disabled');
                            },
                            error : function(xhr) {
                            	ErrorMessage(xhr);
                            }
                        });

            });
        }

        /**
         * When a year selection happens...
         */
        function yearSelection()
        {
            $('tr.vehicle-select td > .product-vehicle-year').bind('change', function() {
                $.ajax(
                        {   url:'/ajax/search/get-vehicle-list/lan/En/'+that.uri,
                            data:{make:$('tr.vehicle-select td > .product-vehicle-make').val(),year:$(this).val()},
                            type:'GET',
                            dataType:'json',
                            success : function(data) {
                                $('tr.vehicle-select td > .product-vehicle-model').empty().append(createOption('','Select Model'));
                                for(x in data) {
                                    $('tr.vehicle-select td > .product-vehicle-model').append(createOption(data[x]['id'],data[x]['vehicleName']));
                                }
                                $('tr.vehicle-select td > .product-vehicle-model').removeAttr('disabled');
                            },
                            error : function(xhr) {
                            	ErrorMessage(xhr);
                            }
                        });

            });
        }

        /**
         * When a model selection happens...
         */
        function modelSelection()
        {
            $('tr.vehicle-select td > .product-vehicle-model').bind('change', function() {
                var vehicleID = $(this).val();
                if(vehicleID == "") return;
                that.vehicle_id = vehicleID;
                if(that.method!="" && typeof(that[that.method])=='function'){
                	that[that.method]();
                }
            });
        }
        
        buildMakes();
        makeSelection();
        yearSelection();
        modelSelection();
	};
}