﻿

var $jq = jQuery.noConflict();
var DialogToShow = "none";


// Global dialog variables
var PictureUploadDialog;

// do stuff when DOM is ready
$jq(document).ready(function() 
{     
   InitEventArticleViewer();
   //InitJCrop();
   InitDialog();    
   ShowDialog();
});


 function InitEventArticleViewer()
 {
	if (!($jq.browser.msie && $jq.browser.version < 7))
	{
		$jq("#EventTabs").tabs();
	};
 }


function ShowHideTab(showSection, tabName, tabSectionName)
{
  var tab = document.getElementById(tabName);
  var tabSection = document.getElementById(tabSectionName);
  
  if (tab != null && tabSection != null)
  {
    if (showSection == 'true')
    {
        tab.style.display = "block";
        tabSection.style.display = "block";
    }
    else
    {
        tab.style.display = "none";
        tabSection.style.display = "none";
    }
  }
}


function InitJCrop()
{
	var imgName = PictureDialog_Prefix + "PictureDialogPreviewImg";
	
	var img = new Image();	
	img.src = $jq("#" + imgName).attr("src");	
	img.onload = function()
	{
		$jq.Jcrop("#" + imgName, 
		{
			bgColor: 'gray', 
			onSelect: storeCoords, 
			aspectRatio: 1 / 1,
			allowResize: true
		});
		
	};

	//~ $jq("#" + imgName).ready(function()
	//~ {
		//~ var jcropApi = $jq.Jcrop("#" + imgName, 
		//~ {
			//~ bgColor: 'gray', 
			//~ onSelect: storeCoords, 
			//~ aspectRatio: 1 / 1,
			//~ allowResize: true
		//~ });
	//~ });
};




function InitDialog()
{
    // JQuery.UI removes the dialog from the form so we need to append it back
    // so that postbacks from any children work.  
    PictureUploadDialog = $jq("#PictureUploadDialog").dialog({
      bgiframe: true, autoOpen: false, height:500, width:700, modal: true, 
      resizable: false, title: 'Upload Your Picture', position: 'center', 
      draggable: true,
		open: function()
		{
			InitJCrop();
		}
    }); 
}




function storeCoords(c) 
{
    jQuery("#" + PictureDialog_Prefix + "X").val(c.x);
    jQuery("#" + PictureDialog_Prefix + "Y").val(c.y);
    jQuery("#" + PictureDialog_Prefix + "W").val(c.w);
    jQuery("#" + PictureDialog_Prefix + "H").val(c.h);
}




function ShowDialog()
{
    if (DialogToShow != "none" && DialogToShow != "")
    {
        $jq('#' + DialogToShow).dialog('open');
        // Now append the Dialog to the form so that and postbacks from
        // child controls work.
        $jq('#' + DialogToShow).parent().appendTo($jq("form:first"));

        // JQuery Dialog does not seem to center the Dialog vertically within the
        // viewport so easiest work around is to scroll to the top where the dialog is.
        $jq('html, body').animate({ scrollTop: 0 }, 'slow');      
    }
}


 

 


