﻿(function($) {
    
    $j.fn.rollback = function(options) {
        var opts = $.extend({}, $j.fn.rollback.defaults, options);
        return this.each(function(){$j(this).hover(function(){$j(this).css({'backgroundImage':$j(this).css('background-image').split('_off').join('_on')})},function(){$j(this).css({'backgroundImage':$j(this).css('background-image').split('_on').join('_off')})});});    
    };

    $j.fn.rollback.defaults = {
        strOn: '_on',
        strOff: '_off'
    };

})(jQuery);

$j = jQuery.noConflict();

$j(document).ready(function() {

    $j('.rollback').rollback();

    $j('.frame ul').each(function() {
		if ($j(this).height() > 160) {
			$j(this).parent().next().show();
		}
    });
	
	$j('.mainfeature').each(function(){
		if ($j(this).height() > 273) {
			$j(this).parent().next().show();
		}
	});
	
	$j('#nextMain').click(function() {
        var ul = $j('.mainfeature');
        var margintop = parseInt(ul.css('margin-top').split('px')[0]) - 273;
		ul.fadeOut('fast',function(){
			ul.animate({ 'marginTop': '-=273px' }, function(){
				ul.fadeIn('fast');
			});
		});
        if (margintop + ul.height() < 273) $j(this).hide();
        if (margintop != 0) $j(this).next().show();
		return false;
    });

    $j('#prevMain').click(function() {
        var ul = $j('.mainfeature');
        var margintop = parseInt(ul.css('margin-top').split('px')[0]) + 273;
		ul.fadeOut('fast',function(){
			ul.animate({ 'marginTop': '+=273px' }, function(){
				ul.fadeIn('fast');
			});
		});
        if (margintop + ul.height() > 273) $j(this).prev().show();
        if (margintop == 0) {
            $j(this).hide();
            $j(this).prev().show();
        }
        return false;
    });

    $j('#subfeature .more').click(function() {
        var ul = $j(this).prevAll('.frame').eq(0).find('ul');
        var margintop = parseInt(ul.css('margin-top').split('px')[0]) - 160;
		ul.fadeOut('fast',function(){
			ul.animate({ 'marginTop': '-=160px' }, function(){
				ul.fadeIn('fast');
			});
		});
        if (margintop + ul.height() < 160) $j(this).hide();
        if (margintop != 0) $j(this).next().show();
    });

    $j('#subfeature .back').click(function() {
        var ul = $j(this).prevAll('.frame').eq(0).find('ul');
        var margintop = parseInt(ul.css('margin-top').split('px')[0]) + 160;
        ul.fadeOut('fast',function(){
			ul.animate({ 'marginTop': '+=160px' }, function(){
				ul.fadeIn('fast');
			});
		});
        if (margintop + ul.height() > 160) $j(this).prev().show();
        if (margintop == 0) {
            $j(this).hide();
            $j(this).prev().show();
        }
    });

    $j('#subfeature1 .more').click(function() {
        var ul = $j(this).prevAll('.frame').eq(0).find('ul');
        var margintop = parseInt(ul.css('margin-top').split('px')[0]) - 160;
        ul.fadeOut('fast',function(){
			ul.animate({ 'marginTop': '-=160px' }, function(){
				ul.fadeIn('fast');
			});
		});
        if (margintop + ul.height() < 160) $j(this).hide();
        if (margintop != 0) $j(this).next().show();
    });

    $j('#subfeature1 .back').click(function() {
        var ul = $j(this).prevAll('.frame').eq(0).find('ul');
        var margintop = parseInt(ul.css('margin-top').split('px')[0]) + 160;
        ul.fadeOut('fast',function(){
			ul.animate({ 'marginTop': '+=160px' }, function(){
				ul.fadeIn('fast');
			});
		});
        if (margintop + ul.height() > 160) $j(this).prev().show();
        if (margintop == 0) {
            $j(this).hide();
            $j(this).prev().show();
        }
    });

    $j('.vidplay').click(function() {
        var swfSrc = '/Common/Flash/MerrickRosso/video.swf?movie=' + $j(this).attr('href') + '&autoplay=true';
        var so1 = new SWFObject(swfSrc, "MerrickRosso", $j('#videoplayer').width(), $j('#videoplayer').height(), "9", "#000000");
        so1.addParam("allowFullScreen", "true");
        so1.addVariable("autoplay", "true");
        so1.write("videoplayer");
        return false;
    });
    
});