/**
 * @author th
 */
//jQuery.noConflict();
var BASE = "http://www.kspace.tv";

var COOKIE_NAME = "_ksu";
var OPTIONS = { expires: 100, domain: 'kspace.tv', path: '/'};

if (!jQuery.cookie(COOKIE_NAME)) {
	jQuery.cookie(COOKIE_NAME, "#null", OPTIONS);
}

jQuery(document).ready(function()
{
	jQuery(".box-title").each(function(){
		jQuery(this).hover(function() {
			jQuery(this).css({"color":"#00d200"});
		}, function() {
				jQuery(this).css({"color":"#696969"});
			// Stuff to do when the mouse leaves the element;
		});
		jQuery(this).click(function(){
			toggleBox(jQuery(this));
		});
	});
	var boxes = jQuery.cookie(COOKIE_NAME);
	if (boxes != null){
		boxes.replace("#null","");
		boxes = boxes.split('#');
			for (var i = 0; i < boxes.length; i++) {
				jQuery('#' + boxes[i]).children('.box-title').removeClass('open');
				jQuery('#' + boxes[i]).children('.box-content').slideUp();
			}
	}
	jQuery(".gallery").each(function(index, obj){
		jQuery(obj).find("a").colorbox({rel:$(obj).attr("id"), maxWidth:"95%", maxHeight:"95%"});
	});

}
);

function toggleBox(elm)
{
	var id = elm.parent().attr("id");
	var chip = jQuery.cookie(COOKIE_NAME);

	if (jQuery(elm).attr("class") == "box-title open"){
		jQuery(elm).removeClass('open');
		jQuery(elm).parent().children('.box-content').slideUp();
	}
	else {
		jQuery(elm).addClass('open');
		jQuery(elm).parent().children('.box-content').slideDown();
	}
	if (chip.search(id) == -1){
			chip = chip.replace("#"+id, "");
			jQuery.cookie(COOKIE_NAME, chip + "#" + id, OPTIONS);
	}
	else {
			chip = chip.replace("#"+id, "");
			jQuery.cookie(COOKIE_NAME, chip, OPTIONS);
	}
}
function openPlayer($this)
{
		var pl = jQuery.trim(jQuery('#jukeboxShell').html());
		pl = escape(pl.replace(new RegExp( "\n", "g" ),""));
		jQuery("#jukebox").children('.box-title').removeClass('open');
		jQuery("#jukebox").children('.box-content').slideUp();
//		win = window.open("http://fairtilizer.com/user/19133?fairplayer=large&start_track=46302&autoplay=1",'p',"width=220,height=350,toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no").focus();
				win = window.open(BASE+"/player-popup/",'p',"width=220,height=350,toolbar=no,menubar=no,status=no,scrollbars=no,resizable=no").focus();
}