/*
OOOGUI - Obliquid Object Oriented Graphic User Interface

OOOGUI is a dynamic CMS that lets you define your data structure 
(objects, relations between objects, queries on objects), and lets
you create public and private HTML pages to view and modify your 
contents.  All through a WYSIWYG interface. 
OOOGUI is multilingual, manages role based permissions, and 
generates for you PHP and SMARTY code that you can customize on 
your needs.

Copyright (C) 2010 Federico Carrara (federico@obliquid.it)

For more information http://obliquid.org/

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/




/* THINGS TO DO IMMEDIATELY */


// admin popup start 
var itemId = "";
var itemLabel = "";
var action = "";
var objectId = "";
var preassignedRelations = "";
var preassignedProperties = "";
function openAdminPopup( id_item, label_object, id_object,  action, preassignedRelations, preassignedProperties )
{
	this.itemId = String(id_item);
	this.itemLabel = label_object;
	this.objectId = String(id_object);
	this.action = action;
	this.preassignedRelations = preassignedRelations;
	this.preassignedProperties = preassignedProperties;
	//alert (this.preassignedProperties);
	//this.preassignedProperties = "ciao";
	window.open("main.php?openerHasVars=yes", 'adminPanel', 'width=1015, height=500, resizable, status, scrollbars=1, location');
}
// admin popup end 


// login module start 
function submitLogin(field)
{
	document.getElementById("loginForm").submit();
}		
function submitLoginOnEnter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13)
	   {
			document.getElementById("loginForm").submit();
			return false;
	   }
	else
	   return true;
}
// login module end 	

//vtip start
this.vtip = function() {    
    this.xOffset = -4; // x distance from mouse
    this.yOffset = -70; // y distance from mouse       
    
    $("[title]").unbind().hover(    
        function(e) {
            this.t = this.title;
            this.title = ''; 
            this.top = (e.pageY + yOffset); this.left = (e.pageX + xOffset);
            
            $('body').append( '<p id="vtip">' + this.t + '</p>' );
                        
            $('p#vtip #vtipArrow').attr("src", 'javascripts/jq/plugin/vtip/images/vtip_arrow.png');
			
            $('p#vtip').css("top", this.top+"px").css("left", this.left+"px").delay(600).fadeIn("slow");
            
        },
        function() {
            this.title = this.t;
            $("p#vtip").fadeOut("slow").remove();
        }
    ).mousemove(
        function(e) {
            this.top = (e.pageY + yOffset);
			if ( this.top < 0 ) this.top = 0;
            this.left = (e.pageX + xOffset - ( $('p#vtip').width() / 2 ) );
			if ( this.left < 0 ) this.left = 0;
                         
            $("p#vtip").css("top", this.top+"px").css("left", this.left+"px");
        }
    );            
    
};
//vtip end

//share button popup
function sharePopup(linkUrl, className)
{
	var moduleWidth = 0;
	var moduleHeight = 0;
	moduleWidth = $(className).outerWidth();
	moduleHeight = $(className).outerHeight();
	
	alert( "to publish this module in your page just copy and past this code:\n<iframe width='"+ moduleWidth +"' height='"+ moduleHeight +"' src='" + linkUrl + "' scrolling='no' frameborder='0'></iframe>" );
	
}
//share button popup end




/* THEN THINGS TO DO ON READY */


$(document).ready(
	function()
	{
		
		//activate all popup for images
		$(".popupImage").ceebox({titles:false,margin:"20",padding:"0",borderWidth:"8px 0px"});
		//activate all popup for flash
		$(".popupFlash").ceebox({titles:false,margin:"20",padding:"0",borderWidth:"8px 0px"});
		
		
		/*
		//activate fading links
		$("a").fadeTo("slow", 0.7); // This sets the opacity of the thumbs to fade down to 60% when the page loads
		$("a").hover(function(){
			$(this).fadeTo(500, 1.0); // This should set the opacity to 100% on hover
		},function(){
			$(this).fadeTo(1500, 0.7); // This should set the opacity to 100% on hover
		});		
		*/
		
		//activate vtips (animated tooltips)
		vtip(); 
		
		//activate jquery togglers
		//Hide (Collapse) the toggle containers on load
		$(".toggle_container").hide(); 
		$(".toggle_trigger").show();
		//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
		$(".toggle_trigger").click(function(){
			//$(this).toggleClass("active").next().slideToggle("slow");
			$(this).toggleClass("active").next().show();
			$(this).toggleClass("active").hide();
			return false; //Prevent the browser jump to the link anchor
		});
		$(".toggle_container").click(function(){
			$(this).toggleClass("active").hide();
			$(this).toggleClass("active").prev().show();
			return false; //Prevent the browser jump to the link anchor
		});
		
	}
);

	
	
	
//FINALLY THINGS TO DO ON LOAD (AFTER ALL IMAGES ARE LOADED)

	
$(window).load(
	function()
	{
		//activate masonry
		$('.masonry').masonry({	animate: true }); //questo è quello in produzione
		$('.masonry').masonry({	animate: true }); //va richiamato due volte altrimenti sbaglia
		//$('.masonry').masonry({	animate: true, columnWidth: 112 }); //esempio
		//$('.moduleBox').masonry({	animate: true }); //esempio
		
		//activate nivo slider
		$('#slider').nivoSlider({
			effect:'fade', //Specify sets like: 'fold,fade,sliceDown'
			slices:1,
			animSpeed:500, //Slide transition speed
			pauseTime:5000,
			startSlide:0, //Set starting Slide (0 index)
			directionNav:true, //Next & Prev
			directionNavHide:true, //Only show on hover
			controlNav:true, //1,2,3...
			controlNavThumbs:false, //Use thumbnails for Control Nav
			controlNavThumbsFromRel:false, //Use image rel for thumbs
			controlNavThumbsSearch: '.jpg', //Replace this with...
			controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
			keyboardNav:true, //Use left & right arrows
			pauseOnHover:true, //Stop animation while hovering
			manualAdvance:false, //Force manual transitions
			captionOpacity:0.8, //Universal caption opacity
			beforeChange: function(){},
			afterChange: function(){},
			slideshowEnd: function(){}, //Triggers after all slides have been shown
			lastSlide: function(){}, //Triggers when last slide is shown
			afterLoad: function(){} //Triggers when slider has loaded
		});
	}
);
	


