// JavaScript Document

if(marquee) $("div#marquee_content").cycle({ timeout: 4000, speed: 500, height: 40, width: 500, left: 5, pause:1, prev: '#pmarq', next: '#nmarq' });

if(lightbox) $("div.lightbox > a").lightBox({fitToScreen: true, overlayOpacity: "0.75"});

$("#listPlace option").show(function(){ $(this).append( $(this).val() ); });
$("#listPlace").change(function(){ location.href='list.php?place='+$(this).val(); });


// Content SubBlock
$("div.content_sb").show( function() {
	if( $(this).attr("title") != "" ){ var title = $(this).attr("title"); }
	else { title = $(this).attr("id"); }
	if( $(this).parent().attr("id")=="content_right"){ var place = "right"; }
	else if( $(this).parent().attr("id")=="content_left"){ var place = "left"; }
	$(this).wrapInner('<div class="c_sb_content '+place+'"></div>').prepend('<div class="c_sb_title '+place+'">'+title+'</div>')
			  .prepend('<div class="c_sb_head '+place+'"></div>').append('<div class="c_sb_foot '+place+'"></div>');
});

// Content MainBlock
if(content_right && content_left){
	$("div#content_main").css({ width: "490px" });
	$("div.content_block").wrapInner('<div class="c_b_content"></div>').prepend('<div class="c_b_head"></div>').append('<div class="c_b_foot"></div>');
} else if(content_right || content_left){
	$("div#content_main").css({ width: "678px" });
	$("div.content_block").wrapInner('<div class="c_b_wcontent"></div>').prepend('<div class="c_b_whead"></div>')
								   .append('<div class="c_b_wfoot"></div>');
} else {
	$("div#content_main").css({ width: "866px" });
	$("div.content_block").wrapInner('<div class="c_b_acontent"></div>').prepend('<div class="c_b_ahead"></div>')
								   .append('<div class="c_b_afoot"></div>');
}

$("div#store_block").wrapInner('<div class="c_b_wcontent"></div>').append('<div class="c_b_wfoot"></div>');

// Alert title
$("div.c_b_title_red, div.c_b_title_yellow").wrapInner('<div style="padding: 0 15px;"></div>');

// Vertical Alignment
if($.browser.mozilla){
	$(".vertical").show( function() { // Vertical-align hack for Firefox
		var height = $(this).height();
		$(this).wrapInner('<div style="height: '+height+'px"></div>');
	});
} else if($.browser.msie && $.browser.version != "8.0") { // Verical-align hack for IE7 and IE6
	$(".vertical").wrapInner('<div></div>').show( function() {
			var parent_height = $(this).height();
			var child_height = $("div", this).height();
			var padding_var = ( parent_height - child_height )/2;
			$(this).css("padding", padding_var+"px 0").height(child_height);
		});	
} else { // Good browsers like Safari, Chrome, and Opera do not have to do a hack.
	$(".vertical").wrapInner('<div></div>');
}

// INPUT Focus
$("input#account, input#password").addClass("input_blur");
$("input#account, input#password").focus( function(){ $(this).removeClass("input_blur").addClass("input_focus"); });
$("input#account, input#password").blur( function(){ $(this).removeClass("input_focus").addClass("input_blur"); });

// Rank and Hits List
if(content_right){
$("#rank_and_hits > div.accordion").accordion({ event: 'mouseover' });
$("#rank hr.rh_list_line:last, #hits hr.rh_list_line:last").addClass("rh_last");
$(".rh_list_title").hover(function(){ $(this).css({ "font-weight": "bold" }); }, function(){ $(this).css({ "font-weight": "normal" }); });
}

// Type Search
$("input#query").keyup( function() {
	$.ajax({
      url: 'php_functions/dosearch.php',
      type: 'POST',
	  cache: false,
      data: {
        type_search: true,
		query: $("input#query").val()
      },
	  dataType: 'html',
      error: function(xhr) { $("#type_search_acceptor").prepend('<span class="err3" style="color: #FC0;">Can\'t Search now...<br /></span>'); },
      success: function(response) { $("#type_search_acceptor").html(response); }
    });
}).focus( function() { $("#type_search").fadeIn(); }).blur( function() { $("#type_search").fadeOut(); });

$(".linkspan").hover(function(){$(this).addClass('hover')}, function(){$(this).removeClass('hover')});