var type = "closed";
var price = "closed";
var country = "closed";

var type_selected = "";
var price_selected = "";
var country_selected = "";



function mouseover(selector){document.getElementById(selector).style.backgroundPosition = 'top'}
function mouseout(selector){document.getElementById(selector).style.backgroundPosition = 'bottom'}


function content_display(selector, closebtn){

	if (selector == "type_content"){
		if(type ==  "closed"){
			document.getElementById(selector).style.display = 'block';
			document.getElementById('type_close').style.display = 'block';
			document.getElementById('price_content').style.display = 'none';
			document.getElementById('price_close').style.display = 'none';

			type = "open";
			price = "closed";


			return;

		} else if(type == "open"){
			type = "closed";
			document.getElementById(selector).style.display = 'none';
			document.getElementById('type_close').style.display = 'none';
			return;
		}
	}


	if (selector == "price_content"){
		if(price ==  "closed"){
			document.getElementById(selector).style.display = 'block'
			document.getElementById('price_close').style.display = 'block'
			document.getElementById('type_content').style.display = 'none'
			document.getElementById('type_close').style.display = 'none'
			price = "open";
			type = "closed";
			return;
		} else if(price == "open"){
			price = "closed";
			document.getElementById(selector).style.display = 'none'
			document.getElementById('price_close').style.display = 'none'
			return;
		}
	}

	if (selector == "enquire_form_content"){
		if(country ==  "closed"){
			document.getElementById(selector).style.display = 'block';
			document.getElementById('enquire_form_close').style.display = 'block';
			country = "open";
			return;

		} else if(country == "open"){
			country = "closed";
			document.getElementById(selector).style.display = 'none';
			document.getElementById('enquire_form_close').style.display = 'none';
			return;
		}
	}


}

function dropdown_selected(dropdown ,selector){

	if (dropdown == "type"){
		document.getElementById('type_selected').innerHTML = selector;
		type_selected = selector;
		type = "closed";
		document.getElementById('type_content').style.display = 'none';
		document.getElementById('type_close').style.display = 'none';
		return;
	}



	if (dropdown == "price"){
		document.getElementById('price_selected').innerHTML = selector;
		price_selected = selector;
		price = "closed";
		document.getElementById('price_content').style.display = 'none'
		document.getElementById('price_close').style.display = 'none'
		return;
	}

	if (dropdown == "country"){
		document.getElementById('country_selected').innerHTML = selector;
		country_selected = selector;
		country = "closed";
		document.getElementById('enquire_form_content').style.display = 'none'
		document.getElementById('enquire_form_close').style.display = 'none'
		return;
	}

}




$(document).ready(function() {
	// simple accordion
	$('#list1a').accordion();
	$('#list1b').accordion({
		header: '.main',
		autoheight: false
	});

	$("a[rel=example_group]").fancybox({
	'transitionIn'		: 'fade',
	'transitionOut'		: 'fade',
	'titlePosition' 	: 'over',
	'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
		return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
	}
	});

	$("a[rel=video_group]").each(function() {
		var $this = $(this);

		$this.click(function(e) {
			e.preventDefault();

			$.fancybox.showActivity();

			$.embedly(
				$this.attr('href'),
				{
					maxWidth: 960,
					autoplay: true,
          key: '490f1d98ec7311e0bd394040d3dc5c07',
          success: function(oembed, dict){
          	$.fancybox(
          		oembed.html,
          		{
          			'titleShow' : false
          		}
          	);
          }
				}
			);
		});
	});

	$('.slideshow').cycle({
		fx: 'fade',
		speed:  1500,
		timeout: 4000
	});

	/*
	$('#buyer_container').hide();
	$('#seller_container').hide(); */


	removeFocusOnAllLinks();

	$('div.sublinkcontainer a.hover_blue').hover(
	//MouseOver
	function(){
		$(this).parent().animate({"right": "-=10px"}, "fast");
		$(this).find('div.new_boat_bullet').css('background-position','top'); //blue this
		$(this).css('color','#7DA2FE'); //blue this
	},
	//MouseOut
	function(){
		$(this).parent().animate({"right": "+=10px"}, "fast");

		if($(this).hasClass('active_navigation') == false) {
			$(this).find('div.new_boat_bullet').css('background-position','bottom'); //white this
			$(this).css('color','#FFFFFF'); //white this
		}
	}
	);

	$('div.sublinkcontainer a.hover_blue').click(function(){
		$('div.sublinkcontainer a.hover_blue').removeClass('active_navigation');
		$(this).addClass('active_navigation');

		$('div.sublinkcontainer a.hover_blue').css('color','#FFFFFF'); //white all
		$('div.sublinkcontainer div.new_boat_bullet').css('background-position','bottom'); //white all

		$(this).find('div.new_boat_bullet').css('background-position','top');  //blue this
		$(this).css('color','#7DA2FE');  //blue this

		newboats_results($(this).attr('href'));
		return false;
	});


});


var scroller  = null;
var scrollbar = null;

var faded = "false";


function linkover(selector) {
	if($("#" + selector).hasClass('active_nav')  == false){
		$("#" + selector).animate({"top": "-=10px"}, "fast");
	}
}

function linkout(selector) {
	if($("#" + selector).hasClass('active_nav') == false){
		$("#" + selector).animate({"top": "+=10px"}, "fast");
	}
}


function sublinkover(selector) {
	$("#" + selector).animate({"right": "-=10px"}, "fast");
	//$("#" + selector+' > div.new_boat_bullet').css('background-position','top');
}

function sublinkout(selector) {
	$("#" + selector).animate({"right": "+=10px"}, "fast");
}

var old = "";

function newboats(){
	if (faded == "false"){
		$('#new_boat_container').fadeIn("slow");
		faded = "true";
	}else{
		$('#new_boat_container').fadeOut("slow");
		$('#new_boat_searchresults_wrapper').fadeOut("slow");
		faded = "false";
	}
}

function newboats_results(selector){
	$('#new_boat_searchresults_wrapper').fadeIn('slow'); //hide to accomplish fadein
	$('.Scroller-Container').html('<p><br/><br/><div style="width:650px;height:360;vertical-align:middle;text-align:center;" align="center"><?php echo $html->image("ajax-loader.gif"); ?><br/>Loading...</div><p>');
	$('.Scroller-Container').load(selector, function(){
		scroller  = new jsScroller(document.getElementById("Scroller-1"), 400, 336);
		scrollbar = new jsScrollbar(document.getElementById("Scrollbar-Container"), scroller, false);
	});
}


function mouseover(selector){document.getElementById(selector).style.backgroundPosition = 'top'}
function mouseout(selector){document.getElementById(selector).style.backgroundPosition = 'bottom'}

function formsubmit(){
	alert (type_selected);
	alert (length_selected);
	alert (price_selected);

	document.frmSearch.submit();
}

function formsubmit() {
	document.preowned_enquiry.submit();
}


function removeFocusOnAllLinks(){

	for(var i=0 ; i < document.links.length ; i++){
		document.links.onclick=blurLink();
	}
}

function blurLink(){
	if (this.blur){this.blur;}
}


