/**
 * @version $Id$
 * @requires jQuery
 */
var base_url_amserv = '';

jQuery(function() {

	/*jQuery('#model-scroll-items').jcarousel({
		animation: 3000, 
		scroll: 5, 
		auto: 3, 
		wrap: 'circular',
		initCallback: function(){			
		}		
	});		*/
	
	jQuery('#model-scroll').tinycarousel({
		interval: true,
		display: 1,
		duration: 1500,
		intervaltime: 3000
	});


	// Load header menu from base page
	/*
	jQuery('#header-menu').load(base_url_amserv+'/?op=header', function(result, status) {
		if (status=='success') {
			jQuery().animateMenu({
				debug                : false,
				menu_height          : 81,
				menu_animation_style : 'fade',
				menu_animation       : 250,
				menu_over_animation  : 500,
				menu_out_animation   : 500,
				menu_over_sensitive  : 350,
				menu_out_sensitive   : 500,
				main_menu_container  : '#mainmenu',
				sub_menu_container   : '#submenu',
				default_main_menu    : 0,
				base_url             : base_url_amserv+'/'
			});
		}
	});
	*/

	// Load footer menu from base page
	/*
	jQuery('#footer-menu').load(base_url_amserv+'/?op=footer', function() { });
	*/

	jQuery('.modelpage .mainmenu li').first().addClass('first');

	jQuery('#model-list ul').last().addClass('last');

	var galleries = jQuery('.ad-gallery').adGallery({start_at_index: 0, scroll_jump: 1, effect: 'fade', thumb_opacity: 1});
	jQuery('.ad-gallery .ad-back, .ad-gallery .ad-forward').css({'opacity': '1'});

	jQuery('.popupwindow').popupwindow();

	jQuery('a[rel="blank"]').attr('target', '_blank')
	jQuery('a[rel="top"]').attr('target', '_top')

	jQuery('.modelpage .mainmenu li').hoverIntent({
		interval: 100,
		over: drops_show,
		timeout: 200,
		out: drops_hide
	});

	jQuery('.techinfo-tabs').tabs({
		//
	});

});

jQuery(function() {
	/*var h_model_list_img = 0;
	var h_mar1 = 0;
	jQuery("#hyundai .modelpage #model-list li img").each(function () {
		h_model_list_img = jQuery(this).width();
		h_mar1 = parseInt((h_model_list_img) / 2);
		jQuery(this).css({"margin-left" : -h_mar1});
	});*/

	/*
	var p_model_list_name = 0;
	var p_mar2 = 0;
	jQuery("#peugeot .modelpage #model-list .info").each(function () {
		p_model_list_name = jQuery('.info-tag', this).height();
		p_model_list_price = jQuery('.price-tag', this).height();
		p_mar2 = parseInt((p_model_list_name - p_model_list_price) / 2);
		jQuery('.price', this).css({"padding-top" : p_mar2});
	});*/

	var p_model_info = 0;
	var p_model_price = 0;
	var p_mar = 0;
	jQuery("#peugeot .modelpage #model-list .info").each(function () {
		p_model_info = jQuery('.info-tag', this).height();
		p_model_price = jQuery('.price', this).height();
		p_mar = parseInt(p_model_info / 2);
		if (p_model_info > p_model_price) {
			jQuery(this).height(p_model_info);
		} else {
			jQuery(this).height(p_model_price);
		}
		jQuery('.price-tag', this).height(p_mar);
		jQuery('.price', this).css({"margin-bottom" : -p_mar});
	});

});

function open_form(id){
	tb_show("", "./?op=form&id="+id+"&popup&width=450&height=220&animate=1");
}

function drops_show(){ jQuery('ul', this).first().fadeIn(400).show(); }
function drops_hide(){ jQuery('ul', this).first().fadeOut(300); }

Cufon.replace('#peugeot #model-scroll ul li .name, #peugeot .modelpage .text-box .right-side h1,  #peugeot #model-list h3', { fontFamily: 'peugeot', hover: true });

Array.prototype.in_array = function(p_val) {for(var i = 0, l = this.length; i < l; i++) {if(this[i] == p_val) {return true;}}return false;}

function countProperties(obj) {var count = "__count__",hasOwnProp = Object.prototype.hasOwnProperty;if (typeof obj[count] === "number" && !hasOwnProp.call(obj, count)) {return obj[count];}count = 0;for (var prop in obj) {if (hasOwnProp.call(obj, prop)) {count++;}}return count;};

featuredcontentglider.init({
		gliderid: "model-adv", //ID of main glider container
		contentclass: "adv", //Shared CSS class name of each glider content
		togglerid: "model-adv-small", //ID of toggler container
		remotecontent: "", //Get gliding contents from external file on server? "filename" or "" to disable
		selected: 0, //Default selected content index (0=1st)
		persiststate: false, //Remember last content shown within browser session (true/false)?
		speed: 500, //Glide animation duration (in milliseconds)
		direction: "rightleft", //set direction of glide: "updown", "downup", "leftright", or "rightleft"
		autorotate: true, //Auto rotate contents (true/false)?
		autorotateconfig: [10000, 10] //if auto rotate enabled, set [milliseconds_btw_rotations, cycles_before_stopping]
})

featuredcontentglider.init({
		gliderid: "colors", //ID of main glider container
		contentclass: "car", //Shared CSS class name of each glider content
		togglerid: "color-controls", //ID of toggler container
		remotecontent: "", //Get gliding contents from external file on server? "filename" or "" to disable
		selected: 0, //Default selected content index (0=1st)
		persiststate: false, //Remember last content shown within browser session (true/false)?
		speed: 500, //Glide animation duration (in milliseconds)
		direction: "rightleft", //set direction of glide: "updown", "downup", "leftright", or "rightleft"
		autorotate: true, //Auto rotate contents (true/false)?
		autorotateconfig: [10000, 10] //if auto rotate enabled, set [milliseconds_btw_rotations, cycles_before_stopping]
})
