/*!
 * GS Javascript V1 - June 2010
 */

/* vendor profile display from proj manager */
function getvendor ( selectedtype )
{
  document.vendorform.viewvendor.value = selectedtype ;
  document.vendorform.submit() ;
}

// project page use
function initMenu() {
  $('#menu ul').hide();
  $('#menu li a').click(
    function() {
        $(this).next().slideToggle('normal');	
      }
    );
  }


$(document).ready(function(){

	$('a.media').media({width:800, height:500});
	/* max upload fix - disabler */
	$('form').submit(function(){
    	$('input:file[value=""]').attr('disabled', true);
	});

	$(".newsticker-jcarousellite").jCarouselLite({
		vertical: true,
		hoverPause:true,
		visible: 4,
		auto:3000,
		speed:1000
	});

  $('img.profile').imgscale({
    parent : '.fixed_box',
	fade : 1000
  }); 

		$('#mycost').priceFormat({
			prefix: '',
			centsSeparator: ',',
			thousandsSeparator: '.',
			centsLimit: 2
		});
		$('#myrentalcost').priceFormat({
			prefix: '',
			centsSeparator: ',',
			thousandsSeparator: '.',
			centsLimit: 2
		});
		$('#myconstructionyear').priceFormat({
			prefix: '',
			centsSeparator: '',
			thousandsSeparator: '',
			limit: 4
		});


	$('#ledgertotal').priceFormat({
		prefix: 'R$ ',
		centsSeparator: ',',
		thousandsSeparator: '.'
	});
	
	$('#mycity').change(function()
	{
		myurl = "includes/bairros.php";
		var mycity = $("#mycity").val();
//		alert(mycity);
		$("#bairrosmodule").load(myurl, {"mycity":mycity});
	});


// MENU MAIN - display menu items
			$('#dock').Fisheye(
				{
					maxWidth: 60,
					items: 'a',
					itemsText: 'span',
					container: '.dock-container',
					itemWidth: 40,
					proximity: 75,
					halign : 'center'
				}
			)

	// Expand Panel
	$("#open").click(function(){
		$("div#panel").slideDown("slow");
	});	
	
	// Collapse Panel
	$("#close").click(function(){
		$("div#panel").slideUp("slow");	
	});		
	
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$("#toggle a").click(function () {
		$("#toggle a").toggle();
	});		
		


	initMenu();


// TREE module
	// Hide all subfolders at startup
	$(".php-file-tree").find("UL").hide();
	
	// Expand/collapse on click
	$(".pft-directory A").click( function() {
		$(this).parent().find("UL:first").slideToggle("medium");
		if( $(this).parent().attr('className') == "pft-directory" ) return false;
	});

	//TABS - proj manag page
	//Default Action
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content
	
	//On Click Event
	$("ul.tabs li").click(function() {
		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content
		var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active content
		return false;
	});



	//DRAG BOX functions
	$('.dragbox')
	.each(function(){
		$(this).hover(function(){
			$(this).find('h2').addClass('collapse');
		}, function(){
			$(this).find('h2').removeClass('collapse');
		})
		.find('h2').hover(function(){
			$(this).find('.configure').css('visibility', 'visible');
		}, function(){
			$(this).find('.configure').css('visibility', 'hidden');
		})
		.click(function(){
			$(this).siblings('.dragbox-content').toggle();
		})
		.end()
		.find('.configure').css('visibility', 'hidden');
	});
	$('.columnleft').sortable({
		connectWith: '.columnleft, .columnright',
		handle: 'h2',
		cursor: 'move',
		placeholder: 'placeholder',
		forcePlaceholderSize: true,
		opacity: 0.4,
		stop: function(event, ui){
			$(ui.item).find('h2').click();
			var sortorder='';
			$('.column').each(function(){
				var itemorder=$(this).sortable('toArray');
				var columnId=$(this).attr('id');
				sortorder+=columnId+'='+itemorder.toString()+'&';
			});
			/*alert('SortOrder: '+sortorder);*/
			/*Pass sortorder variable to server using ajax to save state*/
		}
	})
	$('.columnright').sortable({
		connectWith: '.columnleft, .columnright',
		handle: 'h2',
		cursor: 'move',
		placeholder: 'placeholder',
		forcePlaceholderSize: true,
		opacity: 0.4,
		stop: function(event, ui){
			$(ui.item).find('h2').click();
			var sortorder='';
			$('.column').each(function(){
				var itemorder=$(this).sortable('toArray');
				var columnId=$(this).attr('id');
				sortorder+=columnId+'='+itemorder.toString()+'&';
			});
			/* alert('SortOrder: '+sortorder); */
			/*Pass sortorder variable to server using ajax to save state*/
		}
	})
.disableSelection();



/*	$(".accordiona2 h3").eq(2).addClass("active"); */
/*	$(".accordiona2 p").eq(2).show(); */

	$(".accordiona2 h3").click(function(){
		$(this).next("p").slideToggle("slow")
		.siblings("p:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});


	$(".accordion2 h3").eq(0).addClass("active");
	$(".accordion2 p").eq(0).show();

	$(".accordion2 h3").click(function(){
		$(this).next("p").slideToggle("slow")
		.siblings("p:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});

	$(".accordion3 h3").eq(0).addClass("active");
	$(".accordion3 p").eq(0).show();

	$(".accordion3 h3").click(function(){
		$(this).next("p").slideToggle("slow")
		.siblings("p:visible").slideUp("slow");
		$(this).toggleClass("active");
		$(this).siblings("h3").removeClass("active");
	});


	// Use this example, or...
//	$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
	// This, or...
//	$('#gallery a').lightBox(); // Select all links in object with gallery ID
	// This, or...
	$('a.lightbox').lightBox(); // Select all links with lightbox class
	// This, or...
//	$('a').lightBox(); // Select all links in the page
	// ... The possibility are many. Use your creative or choose one in the examples above



	/* This is basic - uses default settings */
	$("a#single_image").fancybox();
	
	/* iframe link */
	$("a.iframe").fancybox({
				'width'				: '95%',
				'height'			: 600,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
	$("a.iframe_info").fancybox({
				'width'				: '100%',
				'height'			: '85%',
				'autoScale'			: true,
				'scrolling'			: 'yes',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
	/* vendor profile box */
	$("a.iframe_photo").fancybox({
				'width'				:  750,
				'height'			:  550,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe',
				'onClosed'			: function() { parent.location.reload(true); ;}				
			});
	$("a.iframe_cnbc").fancybox({
				'width'				: 450,
				'height'			: 295,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});
/* vendor profile box */
	$("a.vendorprofile").fancybox({
				'width'				:  550,
				'height'			:  420,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe'
			});

	/* vendor profile box */
	$("a.vendoradjust").fancybox({
				'width'				:  820,
				'height'			:  550,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'type'				: 'iframe',
				'onClosed'			: function() { parent.location.reload(true); ;}				
			});

	/* Using custom settings */
	$("a#inline").fancybox({
		'hideOnContentClick': true
	});

	/* Apply fancybox to multiple items */
	$("a.group").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'titlePosition' 	: 'over',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
		}
	});

$("a.vid").click(function() {
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 480,
			'height'		: 350,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
});

$("a.cnbc400").click(function() {
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 400,
			'height'		: 380,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
});
$("a.cnbc425").click(function() {
	$.fancybox({
			'padding'		: 0,
			'autoScale'		: false,
			'transitionIn'	: 'none',
			'transitionOut'	: 'none',
			'title'			: this.title,
			'width'			: 425,
			'height'		: 279,
			'href'			: this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
			'type'			: 'swf',
			'swf'			: {
			   	 'wmode'		: 'transparent',
				'allowfullscreen'	: 'true'
			}
		});

	return false;
});

// SLIDERS - utilize in project commander forms
  //Fixes an animation glitch caused by the
  //div's dynamic height.  Need to set the
  //height style so the slide functions work
  //correctly.
  $("div.slideBody").each(function(){
    $(this).css("height", $(this).height() + "px");
    });

  //hook the mouseup events to each header
  $("div.slidePanel").children(
    "div.slideHeader").mouseup(function(){
 
    //find the body whose header was clicked
    var body = $(this).parent().children("div.slideBody");

    //slide the panel
    if(body.is(":hidden"))
      body.slideDown();
    else
      body.slideUp();
  });

$('#jsddm > li').bind('mouseover', jsddm_open);
$('#jsddm > li').bind('mouseout',  jsddm_timer);

});

document.onclick = jsddm_close;

var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}



function confirmPost()
{
var agree=confirm("Are you sure you want to delete?");
if (agree)
return true ;
else
return false ;
}

function ShowMenuV1(num, menu, max)
{
	//num is selected value, menu is the name of the div, max is the number of divs
	for(i = 1; i <= max; i++){
		//add number onto end of menu
		var menu_div = menu + i;
			//if current show
			if(i == num) {
				document.getElementById(menu_div).style.display = 'block';
			} else {
			//if not, hide
				document.getElementById(menu_div).style.display = 'none';
			}
	}
}


/* for account */
function ShowMenu(num)
	{
			if (num=="")
			{
				document.getElementById("blocker1").style.display = 'none';
				document.getElementById("blocker2").style.display = 'none';
				document.getElementById("blocker3").style.display = 'none';
			}
			if (num=="Gringo Member")
			{
				document.getElementById("blocker1").style.display = 'none';
				document.getElementById("blocker2").style.display = 'none';
				document.getElementById("blocker3").style.display = 'block';
			}
			if (num=="Vendor Partner")
			{
				document.getElementById("blocker1").style.display = 'block';
				document.getElementById("blocker2").style.display = 'block';
				document.getElementById("blocker3").style.display = 'none';
			}
			if (num=="Real Estate Partner")
			{
				document.getElementById("blocker1").style.display = 'none';
				document.getElementById("blocker2").style.display = 'block';
				document.getElementById("blocker3").style.display = 'none';
			}
	}
	
function ShowRentCost(num)
	{
			if (num=="")
			{
				document.getElementById("cost1").style.display = 'block';
				document.getElementById("rent1").style.display = 'none';
			}
			if (num=="Sale")
			{
				document.getElementById("cost1").style.display = 'block';
				document.getElementById("rent1").style.display = 'none';
			}
			if (num=="Rent")
			{
				document.getElementById("cost1").style.display = 'none';
				document.getElementById("rent1").style.display = 'block';
			}

}	
	
/* checkbox function for table displays */
/*  project list pages */
function selectAllCheckBoxes(FormName, FieldName, CheckValue)
	{
		if(!document.forms[FormName])
			return;
		var objCheckBoxes = document.forms[FormName].elements[FieldName];
		if(!objCheckBoxes)
			return;
		var countCheckBoxes = objCheckBoxes.length;
		if(!countCheckBoxes)
			objCheckBoxes.checked = CheckValue;
		else
			// set the check value for all check boxes
			for(var i = 0; i < countCheckBoxes; i++)
				objCheckBoxes[i].checked = CheckValue;
	}	

