$(document).ready(function() {
	
	$(".external").attr("target", "_blank");
	
	// $(".twitter_panel .scrollable").scrollable({ 
	//     // one configuration property 
	// 	vertical: true,
	//     size: 1
	// });
	// .circular().autoscroll({interval: 7000, api: true});
	
	
	if($(".twitter_panel:visible").length > 0){	
		$(".twitter_panel .scrollable").jCarouselLite({
	        btnNext: ".nextPage",
	        btnPrev: ".prevPage",
			vertical: true,
			visible: 1,
			start: 0,
			circular: false
	    });
	}
	
	if($(".twitter_sales_panel:visible").length > 0){
		$(".twitter_sales_panel .scrollable").jCarouselLite({
	        btnNext: ".nextPage",
	        btnPrev: ".prevPage",
			vertical: true,
			visible: 1,
			start: 0,
			circular: false
	    });
	}
    

	
	var site_path = "";
	site_path = (document.location.host == "roy.local") 
		? document.location.protocol + '//' + document.location.host + "/inglis.com.au/httpdocs/" 
		: document.location.protocol + '//' + document.location.host + "/";
	
	if ($("#registrationForm").length > 0)
		$("#registrationForm").validate({});
	
	if ($(".validateThis").length > 0)
		$(".validateThis").validate({});

	// Pop Window
	$('.popup').click(function() {
		var window_width = 780;
		var window_height = 700;
		var left = (screen.width - window_width) / 2;
		var top = (screen.height - window_height) / 2;
		
		var popupWindow = window.open(this.href,'','width='+ window_width +',height=' + window_height +',resizable=yes,scrollbars=yes,menubar=yes,toolbar=no,location=no,screenX='+ left +',screenY='+ top +',left='+ left +',top='+ top);
		return false;
	});
	
	// Pop Window
	$('.saledayPopup').click(function() {
		var window_width = 805;
		var window_height = 880;
		var left = (screen.width - window_width) / 2;
		var top = (screen.height - window_height) / 2;
		
		var popupWindow = window.open(this.href,'','width='+ window_width +',height=' + window_height +',resizable=yes,scrollbars=yes,menubar=yes,toolbar=no,location=no,screenX='+ left +',screenY='+ top +',left='+ left +',top='+ top);
		return false;
	});

	$('.horsePedigree, .popupFull').click(function() {
		
		var window_width = $(window).width() * 0.9;
		var window_height = $(window).height() * 0.9;
		var left = 10;
		var top = 10;
		
		var popupHorse = window.open(this.href, '', 'width=' + window_width + ',height=' + window_height + ',resizable=yes,scrollbars=yes,menubar=yes,toolbar=no,location=no,screenX=' + left + ',screenY=' + top + ',left=' + left + ',top=' + top);
		return false;
	});

	$(".opaq").css('opacity', 0.7);
	$(".opaq_extreme").css('opacity', 0.2);
	$(".opaq_hard").css('opacity', 0.6);
	$(".explore_this").css('opacity', 0.9
			).mouseover (
			function() { jQuery(this).css('opacity', 1); }
			).mouseout(
			function() { jQuery(this).css('opacity', 0.9); }
		);

	// only process links that have some where to go - this is more of a tool used during development.
	$("a").bind('click', function() {
		if ($(this).attr('href') == "") {
			return false;
		}
	});
	
	$(".disabled").each(function() {
		$(this).attr("disabled", "disabled");
	});
	
	
	// $("input[type=file]").filestyle({ 
	//     image: site_path + "themes/inglis/images/file.browse.gif",
	//     imageheight : 30,
	//     imagewidth : 105,
	//     width : 275
	// });
	
	$("form").bind("submit", function() { 
	
		if (jQuery(this).attr("action") == "") {
			alert('No action set; form can not be submitted.');
			return false;
		}
	});
		
	if ($(".sale_page_wide").length == 0) {
		if ($("table.outlined").length > 0 || $("table.sharemarket_table").length > 0)
			setTableWidths();
	}
		
	if ($("param").length > 0)
		$("param").attr("wmode", "transparent");
	else if ($("embed").length > 0)
		$("embed").attr("wmode", "transparent");

	$('.flash').hide();
	$('.flash').fadeIn('slow', function(){
		setTimeout("$('.flash').fadeOut('slow')", 3000);
	});


	$("#search_box #search_input").bind('click', function() {
	
		if ($(this).val() == "Horse name, sale name, or keyword") {
			$(this).val('');
			$(this).removeClass('inactive');
			$(this).addClass('active');
		}
		
	});

	 $(function() {  
	     if ($.browser.msie && parseInt($.browser.version) < 8) {
		  
	         $("#navigation ul li").hover(  
	             function() {  
	                 $(this).addClass("sf");  
	             },  
	             function() {  
	         	    $(this).removeClass("sf");  
	             });  
	     }  
	});

	// $("#navigation").mouseover(function() {
	// 	if ($.browser.msie && parseInt($.browser.version) < 7) {
	// 		$("select option").css('visibility','hidden');
	// 	}
	// });
	// 
	// $("#navigation").mouseout(function() {
	// 	if ($.browser.msie && parseInt($.browser.version) < 7) {
	// 		$("select option").css('visibility','');
	// 	}
	// });

	$("ul.children").mouseover(function() {
		$(this).prev().addClass('hover');
		// if ($.browser.msie && parseInt($.browser.version) < 7) {
		// 	$("ul.children").css('visibility','hidden');
		// }
	});

	$("ul.children").mouseout(function() {
		$(this).prev().removeClass('hover');
		// if ($.browser.msie && parseInt($.browser.version) < 7) {
		// 	$("select option").css('visibility','');
		// }
	});


	$(".printThis").click(function() {
		window.print();
		return false;
	});
	
	if ($("#sharemarket_outer").length > 0) {
		
		if (!($.browser.msie && $.browser.version.substr(0,1) < 7)) {
			$("#sharemarket_outer").corner({ tl: {radius: 15 }, tr: {radius: 15}, bl: {radius: 15}, br: {radius: 15}});
			$("#sharemarket_inner").corner({ tl: {radius: 15 }, tr: {radius: 15}, bl: {radius: 15}, br: {radius: 15}});
		}
	}

	setTimeout('setColHeights()', 2000);
	
	setColHeights();
	tooltip();

});

function setTableWidths() {

	$("table.sharemarket_table").each(function() { 

		var parentWidth = $(this).parent().width();
		var tableMarginLeft = $(this).css("margin-left");
		var tableMarginRight = $(this).css("margin-right");
		
		var setTableWidth = parentWidth - tableMarginLeft.replace("px", "") - tableMarginRight.replace("px", "");
		
		$(this).width(setTableWidth);

	});
				
	$("table.outlined").each(function() { 
		

		var parentWidth = $(this).parent().width();
		var tableMarginLeft = $(this).css("margin-left");
		var tableMarginRight = $(this).css("margin-right");
			
		var setTableWidth = parentWidth - tableMarginLeft.replace("px", "") - tableMarginRight.replace("px", "");
		
		$(this).width(setTableWidth);
		
	});
}

function setColHeights() {

	if ($(".layoutCol").length > 1) {
	
		var maxHeight = 10;
	
		$(".layoutCol").each(function() {
			if ($(this).height() > maxHeight)
				maxHeight = $(this).height();
		});
		
		$(".layoutCol").each(function() {
			$(this).height(maxHeight + 20);
		});
	
	}
	
	return true;
}

// function checkPlugin() {
// 	
// 	var agt = navigator.userAgent.toLowerCase();
// 	var ie = (agt.indexOf("msie") != -1);
// 	var ns = (navigator.appName.indexOf("Netscape") != -1);
// 	var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
// 	var mac = (agt.indexOf("mac")!=-1);
// 	
// 
// 	if (ie && win) { 
// 		// pluginlist = detectIE("Adobe.SVGCtl","SVG Viewer") + detectIE("SWCtl.SWCtl.1","Shockwave Director") + detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") + detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer") + detectIE("QuickTimeCheckObject.QuickTimeCheck.1","QuickTime") + detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player") + detectIE("PDF.PdfCtrl.5","Acrobat Reader"); 
// 		pluginlist = detectIE("PDF.PdfCtrl.5","Acrobat Reader");
// 	}
// 	
// 	if (ns || !win) {
// 		nse = ""; 
// 		for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes.type.toLowerCase();
// 		// pluginlist = detectNS("image/svg-xml","SVG Viewer") + detectNS("application/x-director","Shockwave Director") + detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("audio/x-pn-realaudio-plugin","RealPlayer") + detectNS("video/quicktime","QuickTime") + detectNS("application/x-mplayer2","Windows Media Player") + detectNS("application/pdf","Acrobat Reader");
// 		pluginlist = detectNS("application/pdf","Acrobat Reader");
// 	}
// 	
// }
// 
// function detectIE(ClassID,name) { result = false; document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n'); if (result) return name+','; else return ''; }
// function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }

function checkAdobePlugin() {
		
	var acrobat = new Object();

	acrobat.installed=false;
	acrobat.version='0.0';

	if (navigator.plugins && navigator.plugins.length) { 
		for (var x = 0, l = navigator.plugins.length; x < l; ++x )  {
			if (navigator.plugins[x].description.indexOf('Adobe Acrobat') != -1)
			{
				acrobat.version=parseFloat(navigator.plugins[x].description.split('Version ')[1]);

				if (acrobat.version.toString().length == 1) 
					acrobat.version += '.0';
				
					acrobat.installed = true;
					break;
			}
		}
	
	} else if (window.ActiveXObject) {
		
		for (x=2; x<10; x++)
		{
			try
			{
				oAcro = eval("new ActiveXObject('PDF.PdfCtrl."+x+"');");
				if (oAcro)
				{
					acrobat.installed = true;
					acrobat.version = x + '.0';
				}
			
			} catch(e) {}
		}

		// try and find old-skool PDF
		try
		{
			oAcro4 = new ActiveXObject('PDF.PdfCtrl.1');
			if (oAcro4)
			{
				acrobat.installed = true;
				acrobat.version = '4.0';
			}
			
		} catch(e) {}


		// try and finder newer PDF
		try
		{
			oAcro7 = new ActiveXObject('AcroPDF.PDF.1');
			if (oAcro7)
			{
				acrobat.installed = true;
				acrobat.version = '7.0';
			}
		
		} catch(e) {} 
	}
	
	if (acrobat.installed) {
		return false;
	} else {
		return true;
		// alert('Certain components of this site require the Adobe Plugin for browsers.\nPlease ensure this is corrected to view all features of this site.')
	}
	
}
