/* 
$(window).resize(function () {
	columnConform('.equal-heights > div');
});
$(function () {
	columnConform('.equal-heights > div');
});
$(function () {
	columnConform('.equal-heights > li');
}); */


$(document).ready(function(){

// Searach

// $("body").click(function(e) {
	
	// if ((e.target.className !== "search_options") & (e.target.id !== "search_options_button")) {
		// $("#search_options").hide();
	// }
// });

$(".menu div").mouseenter(function() {
	$("span", this).addClass('highlight');
	$("a", this).addClass('hover');
}).mouseleave(function(){
	$("span", this).removeClass('highlight');
	$("a", this).removeClass('hover');
});

var search_input = $("#q");
var search_input_base_value = search_input.val();

search_input.focus(function() {
	if (this.value == search_input_base_value) this.value = '';
	$("#search").addClass("search-hover");
});

search_input.focusout(function() {
	if (this.value == '') this.value = search_input_base_value;
	$("#search").removeClass("search-hover");
});

$("#search_options_btm_all").click(function() {
	if ($(this).attr('checked')) $(".search_options input[type=checkbox]").attr('checked', true)
		else $(".search_options input[type=checkbox]").attr('checked', false);
});

$(".search_options input[type=checkbox]").click(function() {
	if (!$(this).attr('checked')) $("#search_options_btm_all").attr('checked', false);
});

$("#search_options_button").click(function() {

// $("#search_options").toggle();

	// var search_options = $("#search_options");	
	// if (search_options.css('display') == 'none') {
		// search_options.css('display', 'block');
		// alert('aaga!');
		// }
		// else search_options.css('display', 'none');

});

//
// Blocks resize
$(window).resize(function () {
	columnConform('.equal-heights > div');
});
$(function () {
	columnConform('.equal-heights > div');
});
$(function () {
	columnConform('.equal-heights > li');
});


// popups
$(".with-popup").mouseenter(function(){	
		
	$(".with-popup .popup").css("display", "none");
	$(".popup",this).show(350);
	
	
	// $(".popup", this).css("display", "block");
	
	
	// alert($(".popup",this).css('display'));
	
	// $(".popup",this).fadeIn(350);
}).mouseleave(function(){	
	// $(".popup",this).fadeOut(100);
	$(".with-popup .popup").css("display", "none");
	// $(".popup",this).css("display", "none");
});


// video rotate

$('div[tag|="rotate"]').live("mouseenter mouseleave", function(event){	

	if (event.type == 'mouseenter') {
		rotate($('img[tag|="logo"]', this).attr('id'), $(this).attr('videopref'), $(this).attr('count'));
		$('.info-box', this).css('display', 'none');
	}
	else {
		srotate($('img[tag|="logo"]', this).attr('id'));
		$('.info-box', this).css('display', 'block');
	}

});



// onMouseOver="this.getElementsByTagName('div')[0].style.display = 'inline';" onMouseOut="this.getElementsByTagName('div')[0].style.display = 'none';"

// $(".video div").css('display', 'none');


});




var img = new Array();

function load_img(code, prefix, thumb_count) {
		
	if (img[code] != undefined) {
		document.getElementById(code).src = prefix + img[code]['iteration'] + '.jpg';
		img[code]['iteration']++;
		rotate(code, prefix, thumb_count);
	}	
}

function rotate(code, prefix, thumb_count) {
	
	if (img[code] == undefined) img[code] = new Array();
	if (img[code]['iteration'] == undefined) img[code]['iteration'] = 1;
	
	if (img[code]['iteration'] == 1) {

		img[code]['rotate'] = 1;
		img[code]['furl'] = prefix + '1' + '.jpg';
	}
	
	if (img[code]['iteration'] > thumb_count) img[code]['iteration'] = 1;
	setTimeout("load_img('"+code+"', '"+prefix+"', '"+thumb_count+"')",800);

}

function srotate(code) {
	
	document.getElementById(code).src = img[code]['furl'];
	img[code] = undefined;
}
