var myVar = 1;


function verifyContactForm(){
	
document.getElementById('verified').value = 'true';

}

function randomString( len ) {
	var chars = "0123456789abcdefghiklmnopqrstuvwxyz";
	var randomstring = '';
	for (var i=0; i<len; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

function addBookmark(title,url) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,""); 
	} else if( document.all ) {
		window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
		return true;
	}
}

var defaultSearch = "Search...";







$(document).ready(function() {


	
	// Fix transparent PNGs for IE6
    //$('img[src$=.png]').ifixpng();
    //$('#logo a, p.tagline, #daily-preview .date').ifixpng();
	
	// Maximum results dropdown for event listings
	$("#max_results").change(function() {
		$("#max_form").submit();
	});
	
	// search field default message and autocomplete
	$('#srch_code').focus(function() {
		if ($(this).val() == defaultSearch)
			$(this).val("");
	}).blur(function() {
		if ($(this).val() == "")
			$(this).val(defaultSearch);
	});
	
	$('input#srch_code').autocomplete("/autocomplete/search", {
		width: 216,
		minChars: 2,
		selectFirst: false,
		extraParams: { t:function() {
			return $('#type').val();
		}}
	});
	
	// Hover hints for results icons
	$('.results tbody td.actions a').tooltip({
		showURL: false
	});
	
	// Entrepreneurs image switcher
	$(".image-list li a").each(function(i) {
		$(this).click(function() {			
	        var img = new Image();
	        
	        $(img).load(function () {  
	            $(this).hide();
	            $(this).fadeIn();
	        })
	        .error(function () {
	            alert("There was an error loading the image");
	        })
	        .attr('src', $(this).attr('href'))
	        .attr('alt', $(this).attr('title'))
	        .attr('id', 'current-image');
			
			// display the event details
			$('.switcher h3').html(switcherItems[i][0]);
			$('.switcher .item-details').html(switcherItems[i][1]);
			$('.switcher .item-link a').attr("class", switcherItems[i][2]).html(switcherItems[i][2]).attr("href", switcherItems[i][3]);
	        
	        /* 
	         * ugly code to remove the selected styles from all items then apply to the clicked it. Can't use
	         * normal css class for some reason, IE ignores the image resize
	         */
			$(".image-list li a").css("padding", "0").
			css("background", "none").
			children('img').width(34);
			$(this).css("padding", "2px").
			css("background", "url(/images/bg_switcher_current.gif) no-repeat bottom center").
			css("padding-bottom", "9px").
			children('img').width(30);
	        
	        return false;
	    });
	});
    
    // load the first item
    $(".image-list li:first a").trigger('click');
	
	/* convert certain rel links into popup windows */
	$('a[rel=new]').live("click", function() {
		window.open($(this).attr('href'));
        return false;
	});
	
	$('a[rel=player]').live("click", function() {
		window.open($(this).attr('href'), 'eventPlayer', 'resizable=yes, scrollbars=yes, width=766, height=660');
        return false;
	});
	
	/* modal window setup */
	$('a[rel=modal]').click(function() {
        var mspeed = 0;
        var mwidth = 0;
        var mheight = 0;
        
		var classn = $(this).attr("class");
		var classes = classn.split(" ");
        
		for (var i=0; i<classes.length; i++) {
            if (classes[i].match("speed")) {
                mspeed = classes[i].slice((classes[i].lastIndexOf("_") + 1), classes[i].length);
            } else if (classes[i].match("size")) {
                msizes = classes[i].slice((classes[i].lastIndexOf("_") + 1), classes[i].length).split("x");
                mwidth = msizes[0];
                mheight = msizes[1];
            }
		}
        
        if (mspeed)
            modalSpeed = parseInt(mspeed);
        if (mwidth) {
            $('#modal')
            .css("width", mwidth +"px")
            .css("margin-left", "-"+ (mwidth / 2) +"px");
        }
        if (mheight)
            $('#modal').css("height", mheight +"px");
	});
    
    if ($('#modal').length > 0) {
		$('#modal').jqm({
			trigger: $('a[rel=modal]'),
			ajax: '@href',
			onShow: function(h) {
				h.w.fadeIn(modalSpeed);
			}
		});
	}
	
	// Add to favourites footer menu item
	$('.add-to-favourites').click(function() {
		addBookmark('Boardroom Radio', 'http://www.brr.com.au/');
		return false;
	});
	
	// Disable clicking on certain top level navigation elements
	$('li.static > a', '#navigation').click(function() {
		return false;
	})
	
	// Heading quote cycler
	$('#promotion.cycle').cycle({
		fx:			'fade',
		timeout:	6000,
		speed:		1000,
		height:		'auto',
		random:  	1,
		sync:		0
	});
});