$(document).ready(function() {
    $('#mycarousel').jcarousel({
		buttonNextHTML: '<img src="images/buttons/btn_slideshow_next.gif" width="19" height="67" alt="button next" />',
        buttonPrevHTML: '<img src="images/buttons/btn_slideshow_prev.gif" width="19" height="67" alt="button previous" />',
        scroll: 1,
        auto: 4,
        wrap: "circular",
        animation: "slow"
    });
    $("#mycarousel a").attr("href","javascript:");
    $("#mycarousel a").click(function() {
    	$("#mainImage").attr("src",$(this).children("img").attr("alt"));
    });
	
	$('#listingcarousel').jcarousel({
		buttonNextHTML: '<img src="images/buttons/btn_slideshow_next.gif" width="19" height="67" alt="button next" />',
        buttonPrevHTML: '<img src="images/buttons/btn_slideshow_prev.gif" width="19" height="67" alt="button previous" />',
        scroll: 1,
        auto: 4,
        wrap: "circular",
        animation: "slow"
    });

	
    $("#tabs").tabs({ fxFade: true, fxSpeed: 'fast' });
	
	//$("#tour_nav li a").attr("name",$("#tour_nav li a").attr("href"));
	jQuery.each($("#tour_nav li a"), function(i, val){
			$(this).attr("name", $(this).attr("href"));								  
											  });
	$("#tour_nav li a").attr("href","javascript:");
	$("#tour_nav li a").click(function(){
		$("#tour_applet").attr("src", $(this).attr("name"));
		//$("#tour_applet").html("Test");
	});
	$("#slideshowControl li a.picLink").each(function(){
		$(this).click(function(){
			slideInterval = clearInterval(slideInterval);
			id = $(this).attr("class").replace(/picLink pic-/,"");
			slideSwitch(id);
			slideInterval = setInterval( "slideSwitch()", 5000 );
			return false;
		});
	});
	/*$("#slideshowControl #pauseplay a").click(function(){
			if(window.playing){
				slideInterval = clearInterval(slideInterval);
				window.playing = false;
			} else {
				slideInterval = setInterval( "slideSwitch()", 5000 );
				window.playing = true;
			}
			return false;
	});
	$("#slideshowControl #nextslide a").click(function(){
			if($("#slideshow.lots DIV.active")){
				slideInterval = clearInterval(slideInterval);
				slideSwitch();
				slideInterval = setInterval( "slideSwitch()", 5000 );
			}
			return false;
	});
	$("#slideshowControl #prevslide a").click(function(){
			if($("#slideshow.lots DIV.active")){
				slideInterval = clearInterval(slideInterval);
				currId = $("#slideshow DIV.active").attr("id").replace(/pic-/,"")
				slideSwitch(currId);
				slideInterval = setInterval( "slideSwitch()", 5000 );
			}
			return false;
	});*/
	/*
		$("#tour_nav li a").mouseover(function(){
		if($("this").attr("href")!= "javascript:"){
			$("this").attr("name",$("this").attr("href"))
			$("this").attr("href","javascript:")
			alert($("this").attr("href"));
		}
	});*/
		
/*var c = 0;
	$("#slideshow div").each(function(){ 
		$(this).attr("id") = "image-"+c;	
		c++;
	});
	var c=0;
	$("#mycarousel li").each(function(){    
		$(this).click(function(){    
			slideSwitch(c);				   
		});							  
	});*/
});



/*** 
    Simple jQuery Slideshow Script
    Released by Jon Raasch (jonraasch.com) under FreeBSD license: free to use or modify, not responsible for anything, etc.  Please link out to me if you like it :)
***/

function slideSwitch(i) {
    var $active = $('#slideshow DIV.active');

    if ( $active.length == 0 ) $active = $('#slideshow DIV:last');

    // use this to pull the divs in the order they appear in the markup
	if(typeof(i)!="undefined"){
		$next =  $("#pic-"+i);
	} else {
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow.lots DIV:first');
	}
    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    //setInterval( "adSwitch()", 7000 );
    $(".mlive").cycle({
    	fx: 'fade',
    	timeout: 8000,
    	speed: 1000,
		height: 'auto',
		before: function onAfter(curr, next, opts, fwd){
        //get the height of the current slide
        var $ht = $(this).height();
        //set the container's height to that of the current slide
        //$(this).parent().css("height", $ht);
		$(this).parent().animate({height: $ht}, 500 );

	}
    });
    $("#sideAdds .addSpace").cycle({
    	fx: 'fade',
    	timeout: 5000,
    	speed: 1000
    });
    $("#bannerAdds .addSpace").cycle({
    	fx: 'fade',
    	timeout: 5000,
    	speed: 1000
    });
    $("#slideshow").cycle({
    	fx: 'fade',
    	timeout: 5000,
    	speed: 1000,
    	next: '#nextslide a',
    	prev: '#prevslide a',
    	pause: 1
    });
    $('#pauseplay a').click(function() { 
    	$('#slideshow').cycle('pause'); 
	});
    //slideInterval = setInterval( "slideSwitch()", 5000 );
    //window.playing = true
});


function adSwitch() {
    var $active = $('#adbox DIV.active');

    if ( $active.length == 0 ) $active = $('#adbox DIV:last');

    // use this to pull the divs in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#adbox DIV:first');

    // uncomment below to pull the divs randomly
    // var $sibs  = $active.siblings();
    // var rndNum = Math.floor(Math.random() * $sibs.length );
    // var $next  = $( $sibs[ rndNum ] );


    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}