/*
 * CUSTOM FUNCTIONS - BROOKE
 */

//******************************************************
// HIGHSLIDE CUSTOM
//******************************************************
$(document).ready(function(){
    hs.width = 560;
    //hs.minHeight = 500; 
    //hs.maxHeight = 1000;
    hs.marginLeft = $(document).width() - hs.width - 48;
    hs.targetY = 'menu 10px';

    //is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;

    //******************************************************
    // SAFARI/CHROME FIX for highslide/tinymce
    //******************************************************
    hs.Expander.prototype.onAfterExpand = function () {

        //fix for sizing the highslide correctly of we have a very small screen
        //used for the bug, on 800x600 highslide height wasn't getting fully expanded
        //resizes the highslide to the proper height
        resize_highslide_fix();

        if(typeof(tinymce_textarea_id) != 'undefined') {
            //chrome/safari patch
            //fixes the problem of tinyMce not being editable in chrome within a highslide
            //basically reloads tinyMce once highslide opens
            if (jQuery.browser.safari) {    //http://blog.bestwebframeworks.com/detect-browsers-with-jquery/  //also detects chrome and safari
                try {
                    tinyMCE.execCommand('mceRemoveControl',false,tinymce_textarea_id);
                    tinyMCE.execCommand('mceAddControl',false,tinymce_textarea_id);
                }
                catch(e) {}
            }
        }

        //set focus after highslide popup.
        if(typeof(hs_focus_id) != 'undefined') {
            if(hs_focus_id != '') {
                $(hs_focus_id).focus();
                hs_focus_id = '';
            }
        }
        //set focus after highslide popup.
        if(typeof(tinymce_focus_id) != 'undefined') {
            if(tinymce_focus_id != '') {
                tinyMCE.get(tinymce_focus_id).focus();
                tinymce_focus_id = '';
            }
        }

    }

    //for some reason we need to remove and readd tinymce controls before highslide code initializes (onclick)
    //has something to do we highslide coping tinymce element into another DOM location, safari/chrome doesnt like it for some reason
    //this seems to reinitialze tinymce
    hs.Expander.prototype.onInit = function () {
        if(typeof(tinymce_textarea_id) != 'undefined') {
            if (jQuery.browser.safari) {
                try {                    
                    tinyMCE.execCommand('mceRemoveControl',false,tinymce_textarea_id);
                    tinyMCE.execCommand('mceAddControl',false,tinymce_textarea_id);
                }
                catch(e) {}
            }
        }
    }
    //******************************************************
    // SAFARI/CHROME FIX for highslide/tinymce - END
    //******************************************************



//for records
//
//DYNAMICALLY CHANGE SIZE OF OPEN HIGHSLIDE
//$('#linktest').click(function() {
//    $('#loginFormDiv').css('display', 'block');
//    var hs = parent.window.hs;
//    var exp = hs.getExpander();
//    newHeight = exp.y.full + $('#loginFormDiv').height() + 20;
//    exp.resizeTo(exp.x.full,newHeight);
//});

});

//perhaps only do this when in 800x600? for efficency -brooke reminder
function resize_highslide_fix() {
    var hs = parent.window.hs;
    var exp = hs.getExpander();
    exp.resizeTo(exp.x.full,exp.y.full + 30);
}


//custom right trim frunction
String.prototype.rtrim = function(charToReplace) {

    //get right most character
    if (this.substr(this.length-1, 1) == charToReplace) {
        return this.slice(0, -1)
    }
    else {
        return this;
    }
}


//takes the specific value out of your array
Array.prototype.clean = function(deleteValue) {
  for (var i = 0; i < this.length; i++) {
    if (this[i] == deleteValue) {
      this.splice(i, 1);
      i--;
    }
  }
  return this;
};




//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();
//
//
//alert(BrowserDetect.browser);
