
/* SCROLLING MOOTOOLS CODE */
/* ----------------------------------------------------------------------------------------------------------- */

var element_y;
var swiffy;
var cur_groupid;
var group_sortable = new Array();
var lightbox;
var content;

window.addEvent('load', function() {
	checkScrollerWidth();
	checkImages();
});

function checkImages() {
	var check_w = window.getSize().x + 500;
	var winh = window.getSize().y;
	var divId;
	var xpos;

	var divs = $$('.single_image_holder');
	
	for(var i=0; i<divs.length; i++) {
		if(divs[i].getChildren().length) continue;
		
		divId = divs[i].get('id');
		xpos =  parseInt(divId.substr(1));
		if((parseInt($('main_images').getPosition().x) + xpos) >= check_w) return;		
		
		/*
		if((parseInt($('main_images').getPosition().x) + parseInt(divs[i].get('xpos'))) >= check_w) return;
		var img = new Element('img', {
			'src': divs[i].get('source')
		});
		divs[i].adopt(img);
		*/
	}
}

window.addEvent('resize', function(){			
	checkScrollerWidth();
});

function checkScrollerWidth() {
	if($('scrollbar2') && $('content2') && $('handle2'))
	makeScrollbar( $('content2'), $('main_images'), $('scrollbar2'), $('handle2'), true);
}

function makeScrollbar(content,checkContent,scrollbar,handle,horizontal,ignoreMouse){
	
	if(checkContent.getScrollSize().x < scrollbar.getSize().x) {
		handle.setStyle('display','none');
		return;
	}
	
	handle.setStyle('display','block');

	var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
	
	var slider = new Slider(scrollbar, handle, {	
		steps: steps,
		mode: (horizontal?'horizontal':'vertical'),
		//mode: 'horizontal',	
		onChange: function(step){
			var x = (horizontal?step:0);
			var y = (horizontal?0:step);
			content.scrollTo(x,y);
			checkImages();
		}
	}).set(0);
	
	if( !(ignoreMouse) ){
		$$(content, scrollbar).addEvent('mousewheel', function(e){	
			e = new Event(e).stop();
			var step = slider.step - e.wheel * 30;	
			slider.set(step);					
		});
	}
}

//--------------

function detectBrowser()
	{
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	if ((browser=="Netscape"||browser=="Microsoft Internet Explorer") && (version>=4))
	{
		alert("Your browser is good enough!");
	}
	else
	{
		alert("It's time to upgrade your browser!");
	}
}

function alertBrowser()
{
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
alert("Browser name: "+ browser +", Browser version: "+ version );
}



/*


var mySlide = new Slider($('area'), $('knob'), {
	steps: 480,
	onChange: function(step){
		$('upd').setHTML(step);
	}
}).set(0);
 
$('knob2').setOpacity(0.5);
 

var mySlide2 = new Slider($('area2'), $('knob2'), {
	steps: 20,	
	offset: 5,
	onChange: function(pos){
		$('upd2').setHTML(pos);
	}
 
}).set(8);
 

var mySlide3 = new Slider($('area3'), $('knob3'), {	
	steps: 280,	
	mode: 'vertical',	
	onChange: function(step){
		$('upd3').setHTML(step);
	}
}).set(0);

*/

/* SWFOBJECT VIDEO */
/* ----------------------------------------------------------------------------------------------------------- */

function launch_flash( gallery_dir, image_src, vid_num, vid_width, file_type )
{
	/*
	//	<script type="text/javascript" src="js/AC_OETags.js"></script>
	// Major version of Flash required
	var requiredMajorVersion = 8;
	// Minor version of Flash required
	var requiredMinorVersion = 0;
	// Minor version of Flash required
	var requiredRevision = 0;
	var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	if (hasReqestedVersion)
	{	
	}
	else
	{
		div.style.display = "none";
	}	
	*/
	
	var div = document.getElementById('flash_vid_'+vid_num);
	
	var flashvars = {};
	var params = {};
	var attributes = {};
	
	params.bgcolor = "#000000";
	params.allowscriptaccess = "sameDomain";
	params.allowFullScreen = "true";
	params.scale = "noscale"

	attributes.id = "flash_instance_"+vid_num;
	attributes.name = "flash_instance_"+vid_num;

	if(file_type=='2')
	{
		flashvars.rootDir = ["http://"+location.host+"/"];
		flashvars.slideDir = gallery_dir;
		flashvars.displayType = "news";
		flashvars.flvSrc = image_src;

		swfobject.embedSWF("swfs/hn3-gallery.swf", "flash_vid_"+vid_num, vid_width, "360", "9.0.0", "swfs/expressInstall.swf", flashvars, params, attributes);
	}
	else if(file_type=='3')
	{
		swfobject.embedSWF(gallery_dir+image_src, "flash_vid_"+vid_num, vid_width, "360", "9.0.0", "swfs/expressInstall.swf", flashvars, params, attributes);
	}
}


/* MISC FUNCS */
/* ----------------------------------------------------------------------------------------------------------- */


	function trim( str )
	{
	   str = str.replace(/^\s+/, '');
	   str = str.replace(/\s+$/, '');
	   return str;
	}

	function check_obj(obj, msg)
	{
		if( trim(obj.value) == "" )
		{
			alert( msg );
			obj.focus();
			return false;
		}
		else
		{
			return true;
		}
	}

	function check_obj_or(obj1, obj2, msg)
	{
		if( trim(obj1.value) == "" && trim(obj2.value) == ""  )
		{
			alert( msg );
			if( trim(obj1.value) == "" ){ obj1.focus(); }
			else{ obj2.focus(); }
			return false;
		}
		else
		{
			return true;
		}
	}

	function checkContactForm(frm)
	{

		//alert(frm.name);
		if(!check_obj(frm.name, "Please enter a value for: Name")) return false;
		if(!check_obj(frm.email, "Please enter a value for: E-mail")) return false;
		return true;
	}
	
	function selectFileType(component)
	{
	
		var imageOptions = document.getElementById('image_options');
		var videoOptions = document.getElementById('video_options');
		//alert(component.name);
		//alert(component.value);
		
		if(component.value == 2)
		{
			//VIDEO
			imageOptions.style.display = "none";
			videoOptions.style.display = "block";
		}
		else
		{
			//IMAGE OR SWF
			imageOptions.style.display = "block";
			videoOptions.style.display = "none";		
		}
		return true;
	}	
	
	function validateMandatoryFields(frm, formType, mandatoryFields){

		var errorMsg = "";
		var errorOutput = "";
		
		for (i=0;i<mandatoryFields.length;i++)
		{
			if(frm[mandatoryFields[i]].value == '') errorMsg += mandatoryFields[i]+", ";
			errorOutput += " #"+i+" "+mandatoryFields[i]+" = "+frm[mandatoryFields[i]].value+"; \n";
		}
		//alert(errorOutput);
		
		if(errorMsg != ""){
			alert("Please fill the following fields: "+errorMsg);
			return false;
		}
		else{
			return true;	
		}
	}
	
	function checkEventValid(frm){
		
		var errorMsg = "";
		
		if(frm.event_title.value == '') errorMsg += "title, ";
		if(frm.event_location.value == '') errorMsg += "location, ";
		if(frm.event_details.value == '') errorMsg += "details, ";
		if(frm.event_year.value.length < 4) errorMsg += "year must be in form XXXX, ";

		var dateErrorMsg = '';
		
		dateErrorMsg += verifyDate(frm.event_year.value);
		dateErrorMsg += verifyDate(frm.event_month.value);
		dateErrorMsg += verifyDate(frm.event_start_day.value);
		dateErrorMsg += verifyDate(frm.event_end_day.value);
		if(dateErrorMsg != '') errorMsg += "dates must be numbers";
		
		if(errorMsg != ""){
			alert("Please check the following: "+errorMsg);
			return false;
		}
		else{
			return true;	
		}
	}
	function verifyDate(date){
		
		var dateErrorMsg = '';
		if(date == '') dateErrorMsg += "all date fields, ";
		if(isNaN(parseInt(date))) dateErrorMsg += "dates must me numbers, ";
		
		if(dateErrorMsg != '') return dateErrorMsg;
		else return '';
	}
	
	function verifyDelete(entry){

		input_box=confirm("Are you sure you want to delete "+entry+"?");
		if (input_box==true)return true;
		else return false;
	}	
	
	
	
  
// ZEBRA STRIPE
// ----------------------------------------------------------------------------
function stripe(id) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#eee";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

        // avoid rows that have a class attribute
        // or backgroundColor style
       if (! trs[i].style.backgroundColor) {
       //if (! hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
 		  
          // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
            if (! hasClass(mytd) &&
                ! mytd.style.backgroundColor) {
        
              mytd.style.backgroundColor =
                even ? evenColor : oddColor;
            
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  }	
  // this function is needed to work around 
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  } 	
  
  
  
// DETECT BROWSER
// ---------------------------------------------------------------------------- 
  
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

		