var sidebarOrigTop;

// general settings
$(document).ready(function() { 
	//sidebarOrigTop = $("#sidebar").offset().top;
	
	syncContentHeight();

	// search box - handle "default" text . right now only works on search box!
	var defaultSearchTxt = 'חפשו במאגר לפי שם חברה או תחום';
	$('.search_site .untouched').val(defaultSearchTxt);
	$('.untouched').focus(function() {
		if ($(this).val() == defaultSearchTxt) {
			$(this).removeClass('untouched');
			$(this).val('');
			$(this).blur(function() {
				if (!$(this).val()) {
					$(this).addClass('untouched');
					$(this).val(defaultSearchTxt);
				}
			});
		}
	});
	
	
	// image rotation on index page
	if ($('body').hasClass('home') && !$('body').hasClass('blog')) {
		$('#mainImg').crossSlide({
		  sleep: 2,
		  fade: 1
		}, [
		  { src: 'images/homepage-img1.png' },
		  { src: 'images/homepage-img2.jpg' }
		]);
	}
	
});



// make the sidebar scroll with the window
/*
$(window).scroll(function() {
	var min = sidebarOrigTop;
	var max = $("#footer").offset().top - $("#sidebar").height();
	var newTop = $(window).scrollTop()+sidebarOrigTop;
	if (newTop > max) newTop = max;
	if (newTop < min) newTop = min;
    $("#sidebar").css("top", newTop + "px");
});
*/


function syncContentHeight() {
	if ($('#cse').height() > 0)
		return;
	if ($('#sidebar').height() > $('#content').height())
		$('#content').height($('#sidebar').height());
//	if ($('#cse').height() > $('#content').height())
//		$('#content').height($('#cse').height());
}






/* Functions for cookies */
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

