var small_paper_status = 'hidden';
var cursor_on_small_paper = 'off';
var preloadedImages = new Array();
var gmap;

$(document).ready( function(){							
	if ( !($.browser.safari && $.browser.version < 500) ) {	
		//for each (red) nav image
		$('#shopcp_small_top_navigation img').each( function(i,img) {
			//pre-load associated images
			preloadedImages[i] = new Image;
			preloadedImages[i].src = $(img).attr('src').replace( 'font_color=196,0,10', 'font_color=204,153,51');
		});
	}
							
	$('#shopcp_small_paper').css({ 'top':'-155px','display':'block' });
	$('.shopcp_toplink, .shopcp_toplink_selected').hover(
		function () {
			if ( $(this).attr("class")=='shopcp_toplink' ) { //not selected (not uber)
				$($(this).children()[0]).attr('src', $($(this).children()[0]).attr('src').replace( 'font_color=196,0,10', 'font_color=204,153,51') );
			}
			cursor_on_small_paper = 'on';
			if ( small_paper_status == 'hidden' | small_paper_status == 'being_hidden' ) {
				$('#shopcp_small_paper').stop();
				small_paper_status = 'being_shown';
				$('#shopcp_small_paper').animate({"top": "0px"}, "", "", function() { small_paper_status = 'shown' } );	
			}
			$('#shopcp_small_paper').html( '<img style="margin-left:15px; margin-top:0px;" src="/config_central/shopcp_images/small_paper_images/'+$($(this).children()[0]).attr('alt')+'.gif" width="240px" height="150px;"/>' );
		}, 
		function () {
			if ( $(this).attr("class")=='shopcp_toplink' ) { //not selected (not uber)
				$($(this).children()[0]).attr('src', $($(this).children()[0]).attr('src').replace( 'font_color=204,153,51', 'font_color=196,0,10') );
			}
			cursor_on_small_paper = 'off';
			setTimeout('trytohideit()',2000);
		}
	)
	
	//CREATE A ROLL-OVER FOR THE LOGO, IF IT IS NOT THE HOMEPAGE.
	if ( $('#shopcp_logo a img').attr('src') == '/config_central/shopcp_images/red_logo_for_web_not_print.png' ) {
		//preload the roll-over image
		$("<img>").attr("src", '/config_central/shopcp_images/logo_for_web_not_print.png');
		//define the roll-over
		$('#shopcp_logo').hover(
			function () { $('#shopcp_logo a img').attr('src','/config_central/shopcp_images/logo_for_web_not_print.png'); }, 
			function () { $('#shopcp_logo a img').attr('src','/config_central/shopcp_images/red_logo_for_web_not_print.png'); }
		)
	}
	
	/*
	$('#shopcp_background_objects div').draggable({ 
		start: function () { $(this).css( { "margin-top":"0px", "margin-left":"0px" } ) },
		revert: true
	});
	*/
	
	/*
	// pop out effect
	if(!($.browser.msie)) $('#shopcp_background_objects div').css("opacity",.8);
	$('#shopcp_background_objects div').hover(
		function () {
			var ml = parseInt($(this).css('margin-left'));
			$(this).css('margin-left', ( ml + (ml>0?1:-1)*4 ) +'px' )
			if(!($.browser.msie)) $(this).fadeTo("medium",1);
			//$(this).animate({ marginLeft: (ml+(ml>0?1:-1)*4)+'px', opacity: 1	}, 10 );
			
		}, 
		function () {
			var ml = parseInt($(this).css('margin-left'));
			$(this).css('margin-left', ( ml + (ml<0?1:-1)*4 ) +'px' )
			if(!($.browser.msie)) $(this).fadeTo("medium",.8);
		}
	)
	*/
	if ($("#shopcp_shop_imagegal_holder")) shopcp_toggle_gallery(true);

	if ($('#shopcp_city_gmap').size() > 0){
		if (GBrowserIsCompatible()) {
			// Create and Center a Map
			gmap = new GMap2($('#shopcp_city_gmap').get(0));
			//centered and showing entire continental US
			gmap.setCenter(new GLatLng(38.27268853598097, -95.09765625), 4);
			gmap.addControl(new GSmallMapControl());			
			//Create Geocoding object
			this.geocoder = new GClientGeocoder();
			('#shopcp_city_gmap').id = 'shopcp_city_map';
			
			var pt = new GMarker(new GLatLng($('#ptlat').text(), $('#ptlng').text()));
			//var html = '<p>Shop College Park</p>';
			//GEvent.addListener( pt, 'click', function() {pt.openInfoWindowHtml(html);});
			
			gmap.addOverlay(pt);
			gmap.setCenter(pt.getLatLng(), 16);
		}
	}

} )

function trytohideit() {
	if (cursor_on_small_paper == 'off' & (small_paper_status == 'shown' | small_paper_status == 'being_shown') ) {
		small_paper_status = 'being_hidden';
		$('#shopcp_small_paper').stop();
		$('#shopcp_small_paper').animate({"top": "-155px"}, "slow", "", function() { small_paper_status = 'hidden' } );	
	}
}

function adjustRaggedLine() {
	//ragged line connection transfer function
	var a = $('#shopcp_middle').height()%640;
	var l = 0;
	var r = 0;
	//left side
	if (a<52) l = 2
	else if (a<103) l = 3
	else if (a<103) l = 3
	else if (a<107) l = 2
	else if (a<111) l = 1
	else if (a<147) l = 0
	else if (a<187) l = 1
	else if (a<210) l = 2
	else if (a<225) l = 3
	else if (a<449) l = 2
	else if (a<528) l = 1
	else l = 2
	//right side
	if (a<11) r = 0
	else if (a<75) r = 0
	else if (a<80) r = 1
	else if (a<85) r = 2
	else if (a<99) r = 3
	else if (a<197) r = 3
	else if (a<270) r = 4
	else if (a<300) r = 3	
	else if (a<308) r = 2
	else if (a<450) r = 2
	else if (a<482) r = 1
	else if (a<519) r = 2
	else if (a<532) r = 3
	else if (a<604) r = 4
	else if (a<608) r = 3
	else if (a<611) r = 2
	else if (a<630) r = 1
	else r = 0
	document.getElementById('shop_line_left_image').src = '/config_central/shopcp_images/l'+( l.toString() )+'.png';
	document.getElementById('shop_line_right_image').src = '/config_central/shopcp_images/r'+( r.toString() )+'.png';
}

window.onload = function() {
	if (shopcp_firstLoad) {
		//document.getElementById('shopcp_background').style.display = 'block';
		//document.getElementById('shopcp_fg').style.display = 'block';
		$('#shopcp_fg').show();
		$('#shopcp_background').fadeIn(1000);
	}
	adjustRaggedLine();
	for(ii = 0; ii<=10000; ii+=1000) setTimeout('adjustRaggedLine',ii);
}