//if(!Array.indexOf){
//    Array.prototype.indexOf = function(obj){
//        for(var i=0; i<this.length; i++){
//            if(this[i]==obj){
//                return i;
//            }
//        }
//        return -1;
//    }
//}

var active_quick_search = 'city-of-chicago';
var search_features = 0;

$( document ).ready( function()
{
	//$( '.corner' ).corner( "10px" );
	/**
	 * A warning message appears everytime you click an object in the page which has
	 * a warning class attached to it
	 */
	$( '.warning' ).click( function()
	{
		if( ! confirm( 'Are you sure? This cannot be undone!' ) )
		{
			return false;
		}
		
		return true;
	});
	
	$( '#subnav li a' ).each( function() {
		if( $( this ).attr( 'rel' ) == current_command || $( this ).attr( 'rel' ) == current_url || $( this ).attr( 'rel' ) == complete_url || $( this ).attr( 'href' ) == current_url || $( this ).attr( 'href' ) == complete_url ) 
		{
			$( this ).parent().addClass( 'active' );
		}
	} );
	
	$( '#nav li a' ).each( function() {
		if( $( this ).attr( 'rel' ) == current_command || $( this ).attr( 'rel' ) == current_url || $( this ).attr( 'rel' ) == complete_url || $( this ).attr( 'href' ) == current_url || $( this ).attr( 'href' ) == complete_url ) 
		{
			$( this ).parent().addClass( 'active' );
		}
	} );
	
	$( '.icons li a' ).each( function() {
		if( $( this ).attr( 'rel' ) == current_command || $( this ).attr( 'rel' ) == current_url || $( this ).attr( 'rel' ) == complete_url || $( this ).attr( 'href' ) == current_url || $( this ).attr( 'href' ) == complete_url ) 
		{
			$( this ).addClass( 'active' );
		}
	} );
	
	$( '#sidebar ul li a' ).each( function() {
		if( $( this ).attr( 'rel' ) == current_command || $( this ).attr( 'rel' ) == current_url || $( this ).attr( 'rel' ) == complete_url || $( this ).attr( 'href' ) == current_url || $( this ).attr( 'href' ) == complete_url ) 
		{
			$( this ).parent().addClass( 'active' );
		}
	} );
	
    $( '#list a' ).click( function() {
		
		var image = $( this ).attr( 'rel' );

		$('#normal_photo a img').attr( 'src', image );
		var href_print = $('#print_now').attr( 'rel' ) + '?image=' + image;
		$('#print_now').attr( 'href', href_print );
		$('#print a').attr( 'href', href_print );
	
		return false;
	} );
	
	$( '#print a' ).click( function() { openWindow( $( this ).attr( 'href' ), '', 'scrollbars=yes,width=500,height=600' ); return false; } );
	$( '#print_now' ).click( function() { openWindow( $( this ).attr( 'href' ), '', 'scrollbars=yes,width=500,height=600' ); return false; } );
    $( '#request_info a' ).click( function() { openWindow( $( this ).attr( 'href' ), '', 'scrollbars=yes,width=400,height=500' ); return false; } );
    $( '#send_friend a' ).click( function() { openWindow( $( this ).attr( 'href' ), '', 'scrollbars=yes,width=400,height=400' ); return false; } );
    $( '#request_showing a' ).click( function() { openWindow( $( this ).attr( 'href' ), '', 'scrollbars=yes,width=400,height=500' ); return false; } );
	
    $('.click_ads').each( function() { $( this ).attr( 'href', '/ads/click/params/id/' + $( this ).attr( 'rel' ) ); });
    
    $( '.domtabs li a' ).click( function() {
    	var rel = $( this ).attr( 'rel' );
    	if( rel )
    	{
    		$( '.domtabs li' ).removeClass( 'active' );
    		$( this ).parent().addClass( 'active' );
    		$( '#domtab .' + active_quick_search ).fadeOut();
    		$( '#domtab .' + rel ).fadeIn();
    		active_quick_search = rel;
    		return false;
    	}
    } );
    
    $( '#user_options' ).change( function() {
    	var go_to = $( this ).val();
    	if( go_to ) 
    	{
    		redirectTO( go_to );
    	}
    } );

});

function redirectTO( url )
{
	document.location=url;
}

function openWindow( theURL, winName, features )
{
	window.open( theURL, winName, features );
}
