// This file contains javascript that is to be shared between normal pages and the Pipe editor.
// It should not contain any naked JavaScript (i.e., code that is run when loaded).

// Set up search input
function setupSearchBox() {
	var searchBox = $('#hd-search')
	if (searchBox.length > 0) {
		var input = searchBox.children('.input-text');
		var defaultValue = 'Find a Pipe...';
	
		if(input.val() != defaultValue) searchBox.addClass('focused');
	
		input.focus(function() {
			searchBox.addClass('focused');
			if(input.val() == defaultValue) 
				input.val('');
		});
		
		input.blur(function() {
			if(input.val() == defaultValue || input.val() == '') 
				searchBox.removeClass('focused');
			if(input.val() == '') 
				input.val(defaultValue);
		});
	}
};

// open modal window
function openModalFrame(url,width,height) {
    Shadowbox.open({
        content:    url,
        height:     height,
        player:     "iframe",
        width:      width,
        options: 	sbModalOptions
    });
}

// set up modal window
function setUpModalFrame() {
	var modalForm = $('.modal form');
	if(modalForm.length){
		modalForm.attr('target','_parent');
	}
	var cancelButton = $('.modal #cancel');
	if(cancelButton.length){
		cancelButton.click(function(){
			window.parent.Shadowbox.close();
	    });
	}
} 

// set up navigation
function setupNav() {
	/*
	var createPipe = $('a.create');
	if(createPipe.length){
		createPipe.click(function(){
			openModalFrame($(this).attr('href'),600,410);
	     	return false;
	    });
	}
	
	var copyPipe = $('#copy-pipe');
	if(copyPipe.length){
		copyPipe.click(function(){
			if(!($(this).parent().hasClass('off'))) {
				openModalFrame($(this).attr('href'),600,430);	
				return false;
			}
	    });
	}
	*/
	
	var deletePipe = $('#delete-pipe');
	if(deletePipe.length){
		deletePipe.click(function(){
			openModalFrame($(this).attr('href'),600,220);
	     	return false;
	    });
	}
	
//	var updatePipe = $('#pipe-header h1 .edit');
//	if(updatePipe.length){
//		updatePipe.click(function(){
//			openModalFrame($(this).attr('href'),600,400);
//	     	return false;
//	    });
//	}
//	
//	var updateDesc = $('#pipe-desc .edit');
//	if(updateDesc.length){
//		updateDesc.click(function(){
//			openModalFrame($(this).attr('href'),600,400);
//	     	return false;
//	    });
//	}
}
