$(document).ready(function() {


	$(function() {
		$('.eqheight').equalHeights();
	});
	
	var maxHeight = Math.max($("div.secondary_listing:eq(0)").height(), $("div.secondary_listing:eq(1)").height(), $("div.secondary_listing:eq(2)").height());
	$("div.secondary_listing:eq(0)").height(maxHeight);
	$("div.secondary_listing:eq(1)").height(maxHeight);
	$("div.secondary_listing:eq(2)").height(maxHeight);
	
	var p = url_value('p');
	if (p == '') 
		p = 2;
	var op = url_value('op');
	if (p == 2) {
	
	
		$("div.secondary_listing_title:eq(0)").css({
			"border-top": "10px solid #d1c100"
		});
		$("div.secondary_listing_title:eq(0)").children("a").css({
			"color": "#d1c100"
		});
		$("div.secondary_listing_desc:eq(0)").children("a.more_info").css({
			"color": "#d1c100"
		});
		
		$("div.secondary_listing_title:eq(1)").css({
			"border-top": "10px solid #d1c100"
		});
		$("div.secondary_listing_title:eq(1)").children("a").css({
			"color": "#d1c100"
		});
		$("div.secondary_listing_desc:eq(1)").children("a.more_info").css({
			"color": "#d1c100"
		});
		
		$("div.secondary_listing_title:eq(2)").css({
			"border-top": "10px solid #d1c100"
		});
		$("div.secondary_listing_title:eq(2)").children("a").css({
			"color": "#d1c100"
		});
		$("div.secondary_listing_desc:eq(2)").children("a.more_info").css({
			"color": "#d1c100"
		});
		
	}
	$("ul#s" + p).show();
	$("ul#s" + op).show();
	//	$("li#"+p).children("img").show();	
	//	$("li#"+op).children("img").show();	
	
	/*$("li.main_nav_cont").mouseover(function(){
	 var ulid = $(this).attr("id");
	 $("ul.secnav").hide();
	 $("li.main_nav_cont").children("img").hide();
	 $("li.main_nav_cont").children("a").css({"color":"#FFF"});
	 $(this).children("a").css({"color":"#FFF"});
	 //		$(this).children("img").show();
	 $("ul#s"+ulid).fadeIn();
	 });*/
	$('#pause').click(function() {
		$('#imgspace').cycle('pause');
		return false;
	});
	$('#play').click(function() {
		$('#imgspace').cycle('resume');
		return false;
	});
	
	$('#feature').hover(function() {
		$('#controls').fadeIn();
		//$('#slideshow').css({"margin":"-31px 0 0 4px"});
	}, function() {
		//$('#slideshow').css({"margin":"-100px 0 0 4px"});
		$('#controls').fadeOut();
		// $('#slideshow').css({"margin":"4px 0 0 4px"});
	
	});
	
	function onAfter(curr, next, opts) {
		/*
		
		 
		
		 var desc = $(this).attr("desc");
		
		 
		
		 var name = $(this).attr("name");
		
		 
		
		 $("#capname").html(name);
		
		 
		
		 $("#capdesc").html(desc);*/
		
	}
	
	$.ajax({
		type: "GET",
		url: "./draw/banner.draw.php",
		data: "p=" + p,
		success: function(msg) {
			if (msg.length > 2) {
			
				$("div#header").css({
					"background": "none"
				});
				
				var slide = new Array();
				var slide = msg.split(';');
				$("#slideshow").append(slide[1]);
				if (slide[0] == 0) {
					$('#imgspace').cycle({
						fx: 'fade',
						speed: 1000,
						timeout: 7000,
						next: '#next',
						prev: '#prev',
						after: onAfter
					});
				}
				else if (slide[0] == 1) {
					$('#imgspace').cycle({
						fx: 'scrollDown',
						speed: 1000,
						timeout: 7000,
						next: '#next',
						prev: '#prev',
						after: onAfter
					});
				}
				else if (slide[0] == 2) {
					$('#imgspace').cycle({
						fx: 'turnUp',
						speed: 1000,
						timeout: 7000,
						next: '#next',
						prev: '#prev',
						after: onAfter
					});
				}
				else if (slide[0] == 3) {
					$('#imgspace').cycle({
						fx: 'fadeZoom',
						speed: 1000,
						timeout: 7000,
						next: '#next',
						prev: '#prev',
						after: onAfter
					});
				}
			}
			var desc = $("img.feat").attr("desc");
			var name = $("img.feat").attr("name");
			$("#capname").html(name);
			$("#capdesc").html(desc);
		}
	});
	
	
	
	
	
});

function url_value(name) {
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(window.location.href);
	if (results == null) 
		return "";
	else 
		return results[1];
}
