function appendHeader(path){
	
	$('head').append('<link rel="stylesheet" href="'+path+'" type="text/css" />');
		
}

/**
 * highlight the main and bottom menu when the node is openend.
 */
function highlightMenu(key){
	
	$(document).ready(function(){
		$('.menu-tree .menu-'+key).each(function(){
			$(this).addClass('active');
		});
	});
}

//fix height for box
/**
my boxes height adjustment
**/
function adjustBoxes( myboxid,number ){

	var newHeight = $('#'+myboxid + ' .box-middle .box-middle-middle').innerHeight();
	var parentHeight = parseInt( $('#' + myboxid).parent().css('height') );
		
	if(newHeight <   parentHeight ){
		newHeight = parentHeight;
	}
	
	newHeight = newHeight - number;
	window.setTimeout("doBoxes('"+myboxid+"','"+newHeight+"')",1000);
}

function doBoxes(myboxid,newHeight){
	
	$('#'+myboxid + ' .box-middle-middle').css('height',( newHeight  )+'px');
	$('#'+myboxid + ' .box-middle-left').css('height',newHeight+'px');
	$('#'+myboxid + ' .box-middle-right').css('height',newHeight+'px');
}

//document load bind hooks and events
var transitionTime = 10000;
$(document).ready(function(){
	
	window.setTimeout("goHomePlayer()",transitionTime);
	
	$("#myCaroussel").carousel({
       	dispItems: 7,
       	animSpeed: "slow",
       	autoSlide: true,
       	loop: true,
		autoSlideInterval: transitionTime,
		delayAutoSlide: transitionTime
	});
	
	//extract link value of property title and encapsulate it to the entire record box division
	bootstrapProperties();

	//extract link value of portfolio image and encapsulate it to the entire record box division
	bootstrapPortfolio();
	
	autoplaypreviewProperty();
	
	$('#block_properties_homepage #myCaroussel ul li img').each(function(){
		$(this).attr('align','absmiddle');
	});
});

/**
 * Home page player
 */
var needle = 0;
var maxneedle = 0;
function goHomePlayer(){
	maxneedle = $('#block_homepage_images_homepage').children().length;
	if(maxneedle == 1)
		return false;
	$('#block_homepage_images_homepage .item-'+needle).hide(100);
	
	needle++;
	
	if(needle >= maxneedle)
		needle = 0;
	
	$('#block_homepage_images_homepage .item-'+needle).fadeIn(800);
	
	window.setTimeout("goHomePlayer()",transitionTime);
}

/**
 * properties link encapsulation
 */
function bootstrapProperties(){
	$(".properties-record").each(function(){
		var link = $(this).children(".box-middle").children(".box-middle-middle").children(".record").children("h3").children("a").attr('href');
		
		$(this).click(function(){
			window.location.href= link;
		});
	});
}

/**
 * portfolio link encapsulation
 */
function bootstrapPortfolio(){
	$(".portfolio-record").each(function(){
		var link = $(this).children(".box-middle").children(".box-middle-middle").children(".record").children(".image").children("a").attr('href');
		
		$(this).click(function(){
			window.location.href= link;
		});
	});	
}

/**
	properties node javascript images bootstrap
**/
var onoff = true;
function bootstrappropImages(){
			
	$("#node .timage table td a img").click(function(){
		
		$('#node .timage table td a img').each(function(){
			$(this).removeClass('active');
			$(this).parent('a').children('span').removeClass('active');
		});
		
		window.clearTimeout( ppTimeout );
		var linkVal = $(this).parent('a').parent('td').children('div').html();
		$(this).addClass('active');
		$(this).parent('a').children('span').addClass('active');
		$("#propFirstPreview").hide();
		$("#propFirstPreview").html(linkVal);
		
		$("#propFirstPreview").fadeIn();
		$("#propFirstText").html( $(this).attr("title") );
		
		$('html, body').animate({scrollTop: '80px'}, 600);
		onoff = true;
		return false;
	});
	
	$("#node .pimages #icons #expandicon").click(function(){
		
		var original = $('#propFirstPreview').children('img').attr('src').replace("/thumbnail-550/","/original/");
		var originalImage = new Image();
		originalImage.src = original;
		
		var winW = originalImage.width+20;
		var winH = originalImage.height+10;
		//winW = (winW < 500) ? 500 : winW;
		//winH = (winH < 500) ? 500 : winH;
		
		var popupImage = window.open( original, "", "top=100,left=100,width="+winW+",height="+winH);
		return false;
	});
	
	$("#node .pimages #icons #printicon").click(function(){
		
		var original = $('#propFirstPreview').children('img').attr('src').replace("/thumbnail-550/","/original/");
		var originalImage = new Image();
		originalImage.src = original;
		
		var winW = originalImage.width+20;
		var winH = originalImage.height+10;
		winW = (winW < 500) ? 500 : winW;
		winH = (winH < 500) ? 500 : winH;
		
		var popupImage = window.open( original, "", "top=100,left=100,width="+winW+",height="+winH);
		popupImage.onload = function(){popupImage.print()};
		return false;
	});
}

/**
	bind an automatic player for the images of the properties
**/
var ppIndex = 0;
var ppMax 	= 0;
var ppTimeout = null;
function autoplaypreviewProperty(){
	
	ppMax = $("#node .timage td").children().length;
	if(ppMax > 1){
		ppTimeout = window.setTimeout("goPPPlayer()",transitionTime);
	}
}

function goPPPlayer(){
	
	var ppImages = $("#node .timage td").children('a');
	
	
	$('#node .timage td a').each(function(){
		$(this).removeClass('active');
		$(this).children('span').removeClass('active');

	});
	
	$("#propFirstPreview").hide();
	ppIndex++;
	
	if( ppIndex > ppMax-1 )
		ppIndex = 0;
	
	var linkVal = $(ppImages[ppIndex]).parent('td').children("div").html();
	
	$("#propFirstPreview").html(linkVal);
	$("#propFirstPreview").fadeIn();
	
	$("#propFirstText").html( $(ppImages[ppIndex]).attr("title") );
		
	$(ppImages[ppIndex]).children("span").addClass('active');
	$(ppImages[ppIndex]).children("img").addClass('active');
		
	ppTimeout = window.setTimeout("goPPPlayer()",transitionTime);
	
}


