//var img_names = new Array();
var doc_loaded = false;
var current_thumb;

//document.observe("dom:loaded", function () {
//Event.observe(window, 'load', function() { << OLD prototype stuff
jQuery(document).ready(function () {

	doc_loaded = true;
	current_thumb = jQuery('#image_gallery A')[0];
	
	for(var i =0;i<jQuery('SPAN.phone_number').length;i++){
		jQuery('SPAN.phone_number')[i].innerHTML = phone_number;
	}

	if (jQuery('#open_replyto') != undefined) {

		jQuery('#open_replyto').bind("click",function(){
			openReplyTo();
		});	
		jQuery('#open_replyto_bottom').bind("click",function(){
			openReplyTo();
		});
		jQuery('#close_replyto').bind("click",function(){
			jQuery('#back_spam').css(
			  'display', 'none'
			);
			jQuery('#open_replyto').css({
			  'background': 'url(' + baseStaticUri + '/images/email.gif) no-repeat 10px 5px',
			  'color': '#000066'
			});
		});	
		
		jQuery('#open_report_ad').bind("click",function(){
			this.blur();
			jQuery('#report_ad').css({
			  'display': 'block'
			});
			this.style.color = '#666666';
			this.style.cursor = 'default';
			this.style.textDecoration  = 'none';
			
			//this.bind("click",function(){});
			
			for(var i =0;i<jQuery('DIV.successMsg').length;i++){
				jQuery('DIV.successMsg')[i].css({
				  'display': 'none'
				});
			}
		});
	}
	
	//check the cookie and add js check to the form

	if(!Get_Cookie('reply_count')){
		Set_Cookie('reply_count', '0', '', '/', '', '' );
	}
	if(reply_count = Get_Cookie('reply_count')){
		if(reply_count<4){
			jQuery('#back_spam').append('<input type="hidden" name="cookieEnabled" value="1" />');
			jQuery('#captcha_field').html('');
		}
	}

});

function change_img(img_id, element, iframeUrl){
	if(doc_loaded){
		jQuery(element).css({
		  'borderColor': '#FC0'
		});
		jQuery(current_thumb).css({
		  'borderColor': '#CACACA'
		});
		current_thumb = element;
		
		if (iframeUrl.length > 0) {
			jQuery('#big_img').html('<iframe src="' + iframeUrl + '" width="400" height="320" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></iframe>');
		} else {
			jQuery('#big_img').html('<img width="400" height="320" src="' + img_names[img_id] + '" >');
		}
	}
}

function openReplyTo(){
	jQuery('#back_spam').css({
	  'display': 'block'
	});
	jQuery('#reply_sender_email').focus();
	jQuery('#open_replyto').css({
	  'background': 'url(' + baseStaticUri + '/images/email_o.gif) no-repeat 10px 5px',
	  'color': '#666666'
	});
}

function markAd(post_id,type) {
	var url = "/review/review.php";
	jQuery.ajax({
		  url: url,
		  type: "POST",
		  data: "post_id=" + post_id + '&review='+type,
		  dataType: "html",
		  success: function(data) {
				jQuery("#report_ad").html(data);
		  }
		});
//	new Ajax.Request(url, {
//		method: "post",
//		postBody: "post_id=" + post_id + '&review='+type,
//		onSuccess: function(transport) {
//			var reviewBar = $("report_ad");
//			reviewBar.update(transport.responseText);
//		}
//	});
}

function Set_Cookie( name, value, expires, path, domain, secure ){
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ){
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ ){
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );

		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name ){
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ){
		return null;
	}
}

var featureselected = 0;

function featureChange(action){
	if(action==1){
		featureselected++;
	}else{
		featureselected--;
	}
	
	if(featureselected<0)featureselected=0;
	
	if(featureselected>0){
		jQuery('#order_btn').show();
		jQuery('#order_btn_grey').hide();
	}else{
		jQuery('#order_btn_grey').show();
		jQuery('#order_btn').hide();
	}
}
