var $j = jQuery.noConflict();

$j(function(){
	// External Link with callback function
	$j("#slide-jump").click(function(){
		$j('#slider2').anythingSlider(4, function(slider){ /* alert('Now on page ' + slider.currentPage); */ });
		return false;
	});
	// External Link
	$j("a.muppet").click(function(){
		$j('#slider1').anythingSlider(5);
		$j(document).scrollTop(0);
		return false;
	});

	// Report Events to console & features list
	$j('#slider1, #slider2').bind('before_initialize initialized swf_completed slideshow_start slideshow_stop slideshow_paused slideshow_unpaused slide_init slide_begin slide_complete', function(e, slider){
		// show object ID + event (e.g. "slider1: slide_begin")
		var txt = slider.$el[0].id + ': ' + e.type + ', now on panel #' + slider.currentPage;
		$j('#status').text(txt);
		if (window.console && window.console.firebug){ console.debug(txt); } // added window.console.firebug to make this work in Opera
	});

	// Theme Selector (This is really for demo purposes only)
	var themes = ['minimalist-round','minimalist-square','metallic','construction','cs-portfolio'];
	$j('#currentTheme').change(function(){
		var theme = $j(this).val();
		if (!$j('link[href*=' + theme + ']').length) {
			$j('body').append('<link rel="stylesheet" href="css/theme-' + theme + '.css" type="text/css" media="screen" />');
		}
		$j('#slider1').closest('div.anythingSlider')
			.removeClass( $j.map(themes, function(t){ return 'anythingSlider-' + t; }).join(' ') )
			.addClass('anythingSlider-' + theme);
	});

	// Add a slide
	var imageNumber = 1;
	$j('button.add').click(function(){
		$j('#slider1')
			.append('<li><img src="images/slide-tele-' + (++imageNumber%2 + 1)  + '.jpg" alt="" /></li>')
			.anythingSlider(); // update the slider
	});
	$j('button.remove').click(function(){
		if ($j('#slider1').data('AnythingSlider').pages > 1) {
			$j('#slider1 > li:not(.cloned):last').remove();
			$j('#slider1').anythingSlider(); // update the slider
		}
	});

});

$j(function(){
	$j('#slider2').anythingSlider({
		width               : 530,   // if resizeContent is false, this is the default width if panel size is not defined
		height              : 530,   // if resizeContent is false, this is the default height if panel size is not defined
		resizeContents      : false, // If true, solitary images/objects in the panel will expand to fit the viewport
		autoPlay            : false,
		enablePlay          : false,
		buildArrows         : false,
		hashTags            : false,
		startStopped        : true,  // If autoPlay is on, this can force it to start stopped
		navigationFormatter : function(index, panel){ // Format navigation labels with text
			return ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'][index - 1];
		}
	});
});

$j(document).ready(function(){
$j("#myform").validate({
	debug: false,
	submitHandler: function(form) {
		// do other stuff for a valid form
		$j.post('/submit.php', $j("#myform").serialize(), function(data) {
			$j('#results').html(data);
		});
	}
});
});

window.addEvent("domready", function() {
	initImageZoom();
});
