// JavaScript Document
function aj(url,container,js_function)
{
	
	$(".ajax_loader").show();
	
	$.get(url, function(data){
		
		$(container).html(data);
		
		if (js_function != null) {
			eval(js_function);
		}
		
		$(".ajax_loader").hide();
	});
	return false;
}

function scroll_init()
{
	// Scrollable
	if ($('div#scrollable').length > 0) {
		$('div#scrollable').scrollable({
			size: 1,
			horizontal: true
		});
	}
}


function rss_init(){
	
	if ($('div.rssfeed').length > 0 ) {
		$('div.rssfeed').each(function(){
			aj($(this).attr('title'), '#' + $(this).attr('id'), 'scroll_init()');
		});
	}
}

function open_elements(){
	
	var loc = window.location.href;

	var hashArr = loc.split('#');

	if (hashArr.length > 1) {
		$('.' + hashArr[1] + ', #' + hashArr[1]).show();
	}
}

// Once DOM has loaded
$(document).ready(function(){
	$('.submenu ul li a').click(function(){
		if ($(this).parent('li').children('ul').length > 0) {
			if ($(this).parent('li').hasClass('active')) {
				//$(this).parent('li').children('ul').slideUp(function(){
					$(this).parent('li').removeClass('active');
					$(this).parent('li').addClass('inactive');	
				//});
			}
			else {
				//$(this).parent('li').children('ul').slideDown(function(){
					$(this).parent('li').removeClass('inactive');
					$(this).parent('li').addClass('active');
				//});
			}
			return false;
		}
	});
	
	//open_elements();
	
	rss_init();
	init_slider();
	
});


function init_slider(){

	if ($("#slider").length > 0) {
		$("#slider").slider({
			range: true,
			min: 0,
			max: 6,
			values: [0, 1],
			slide: function(event, ui){
			
				//$(".bound").removeClass('blue_box');
				
				for (var counter = 0; counter <= $(".bound").length; counter++) {
					if (counter <= ui.values[0] || counter > ui.values[1]) {
						$("#price_" + counter).removeClass('blue_box');
						$("#price_" + counter).slideUp();
					}
				}
				
				var difference = ui.values[1] - ui.values[0];
				
				for (var counter = ui.values[0]; counter <= ui.values[1]; counter++) {
					$("#price_" + counter + ":hidden").slideDown();
					$("#price_" + counter).removeClass('blue_box');
				}
			}
		});
	}
}

function ec_toggle( selector )
{
	if ($(selector).hasClass('blue_box')) {
		$(selector+' .more').slideUp();
		$(selector).removeClass('blue_box');
	}
	else {
		$(selector+' .more').slideDown();
		$(selector).addClass('blue_box');
		
	}
	return false;
}


function embed_player(videoid,container,thumbpath,baseurl)
{
	flowplayer(container, baseurl + "/assets/player/flowplayer.commercial-3.1.0.swf",{
		key : '#@7d8a52cb90b6a12cf28',
		clip: { 
		    url: videoid, 
		   	urlResolvers: 'xmlresolver', 
			autoPlay:false
		}, 
		plugins: { 
		   	xmlresolver: { 
		        url: baseurl + 'assets/player/plugins/xmlconnect/xml-connect.swf' 
		    } 
		},
		canvas:  { 
		    background: '#000000 url(' + thumbpath + ') no-repeat center',
			backgroundGradient: 'none'
		}
		
	});
}

function clearfield(elem){
	if(elem.value==elem.defaultValue){
		$(elem).val('');
		$(elem).removeClass('empty');
	}
}