/*================================ 
Cleveland Vibrator
 
Last Updated By: EKS
Last Updated: 2/1/2011
Updated : Commented out $('input.text, textarea.text').clearDefault();
================================*/

jQuery(document).ready(function ($) {


    /*================================================
    Home Page Slider
    ================================================*/
   
    $('#slider').cycle({
        //fx: 'scrollLeft',
		fx: 'fade',
        timeout: 7000,
        cleartype: 1
    });


    /*================================================
    Sub Navigation
    ================================================*/
    $('#content div#navigation ul li.second-level:last-child').after('<li class="second-level bottom-cap" />');

    if ($.browser.msie) {
        $('#content div#navigation ul li.fifth-level.selected > a').css({
            'background-position': 'right 2px'
        });
    }


    /*================================================
    Cufon Settings
    ================================================*/
   
    /*---- OnRamp ----*/
    Cufon.replace('#content div#navigation ul li a.cufon', { fontFamily: 'OnRamp', textShadow: '1px 1px 2px #d2d2d2' });
    Cufon.replace('#header ul.nav.contact li.account div.not-signed-in', { fontFamily: 'OnRamp', textShadwow: '1px 1px 1px #ffffff', hover: true });
    Cufon.replace('#header ul.nav.contact li.account div.signed-in', { fontFamily: 'OnRamp', textShadwow: '1px 1px 1px #ffffff', hover: true, ignoreClass: 'nocufon' });

    /*---- Futura ----*/
    Cufon.replace('#content div#article h1', { fontFamily: 'Futura', textShadow: '0px 1px 0px #d2d2d2' });
    Cufon.replace('#content div#article h2', { fontFamily: 'Futura' });
    Cufon.replace('#content div#navigation div#section-name', { fontFamily: 'Futura', textShadow: '0px 1px 2px #d2d2d2' });
    Cufon.replace('#content .listing .listing-item h3 a', { fontFamily: 'Futura', textShadow: '0px 1px 2px #d2d2d2', hover: true });
    Cufon.replace('#content.home div#features div.feature h3', { fontFamily: 'Futura', hover: true, textShadow: '1px 1px 2px #00433a' });
    //Cufon.replace('#content.home div#news div.article h2:not(".no-cufon")', { fontFamily: 'Futura', hover: true });
    Cufon.replace('#content.product div.product-info h2', { fontFamily: 'Futura' });
    Cufon.replace('#modal-popup h2', { fontFamily: 'Futura' });
    Cufon.replace('#content div#article .related-content div.tab-content-wrapper div.tab-content h3', { fontFamily: 'Futura', hover: true });
    Cufon.replace('#content.quote-request .quote-form fieldset legend', { fontFamily: 'Futura' });
    Cufon.replace('#content.quote-request .quote-form fieldset.product-filter label', { fontFamily: 'Futura' });
    Cufon.replace('#content.search-results .keyword-search ul.form label', { fontFamily: 'Futura' });


    /*================================================
    Home Feature Learn More Bar
    ================================================*/
    $('<ul><li class="feature-1">&nbsp;</li><li class="feature=2">&nbsp;</li><li class="feature-3">&nbsp;</li></ul>').appendTo('#content.home div#features div.learn-more-bar');

    /*---- Z-Index Work around for IE7 ----*/
    var learnMoreLink = [];
    var learnMoreBar = [];
		
		
		

    if ($.browser.msie && $.browser.version == 7) {
		
		 $('#content.home div#news div.article h2').addClass('no-cufon');

        $('#content.home div#features div.learn-more-bar ul li').each(function (idx) {

            learnMoreBar[idx] = $(this);
        });

        $('div#content.home div#features div.feature a.learn-more').each(function (idx) {
            learnMoreLink[idx] = $(this);
            $(learnMoreLink[idx]).clone().appendTo($(learnMoreBar[idx]));
        });
    }
        
    Cufon.replace('#content.home div#news div.article h2:not(".no-cufon")', { fontFamily: 'Futura', hover: true });


    /*================================================
    Equal Columns
    ================================================*/
    equalHeight($('div#content.home div#features div.feature'));
    equalHeight($('div#content.home div#features div.feature div.inner'));


    /*================================================
    Modal
    ================================================*/
    $('#modal-popup').jqm({
        modal: true,
        trigger: '.modal-trigger',
        overlay: 100,
        overlayClass: 'modal-overlay',
        closeClass: 'modal-close'
    });

    $('.modal-overlay').live('click', function () {
        $('#modal-popup').jqmHide();
    });

    $('#modal-popup2').jqm({
        modal: true,
        trigger: '.modal-trigger2',
        overlay: 100,
        overlayClass: 'modal-overlay2',
        closeClass: 'modal-close2'
    });

    $('.modal-overlay2').live('click', function () {
        $('#modal-popup2').jqmHide();
    });


    /*================================================
    Product Landing
    ================================================*/
    $('#content.product-landing div.listing div.listing-item:nth-child(2n)').addClass('row-end');


    /*================================================
    Products Detail Page
    ================================================*/
    $("#content.product ul.tabs").tabs("div.tab-content-wrapper div.tab-content", {
        tabs: 'li'
    });

    $('#content.product div.product-info div.schematics div.dimensions div.diagram-key:nth-child(2n)').addClass('row-end');

    var productH2Width = $('#content.product div.product-info h2').width();
    var newProductH2Position = (700 - productH2Width) / 2;

    $('#content.product div.product-info h2').css('left', newProductH2Position);

    $('#content.product div#article .related-content div.tab-content-wrapper div.tab-content.related-documents div.listing-item:nth-child(3n)').addClass('row-end');
    $('#content.product div#article .related-content div.tab-content-wrapper div.tab-content.related-applications div.listing-item:nth-child(2n)').addClass('row-end');
    $('#content.product div#article .related-content div.tab-content-wrapper div.tab-content.related-products div.listing-item:nth-child(2n)').addClass('row-end');
    $('#content.product div#article .related-content div.tab-content-wrapper div.tab-content.related-industries div.listing-item:nth-child(2n)').addClass('row-end');


    /*================================================
    Industry Landing
    ================================================*/
    $('#content.industry-landing div.listing div.listing-item:nth-child(2n)').addClass('row-end');


    /*================================================
    Industry Detail
    ================================================*/
    $('#content.industry-detail div.listing div.listing-item:nth-child(2n)').addClass('row-end');


    /*================================================
    Forms
    ================================================*/
   // $('input.text, textarea.text').clearDefault();

    if (($.browser.mozilla) || ($.browser.msie && $.browser.version == 9)) {
        $('ul.form input.text').css({
            'padding-top': '0px',
            'height': '34px'
        });
    }

    $('select.selectbox').sSelect({
        ddMaxHeight: '300px'
    });
	
	if ($.client.os == "Windows"){	
		$('select.selectbox').parent().addClass('windows');	
	}
	
	var selectHeight = 0;
	
	$('#content div#article ul.newList').each(function(){
		
		selectHeight = $(this).height();
		
		//alert(selectHeight);
			
		if(selectHeight < 300) {
			$(this).parent().addClass('no-scroll');	
		}
		
	});
	
	
	
	

    //$('table.form input:radio ~ label').wrapAll('<span />');

    //$('table.form td.radiobutton').splitUp(2, '<span />');


    $('input:checkbox').after('<a href="#" class="check">Check</a>');
    $('input:radio').after('<a href="#" class="radio">Radio</a>');
    $('.radiobutton input:first-child').parent().addClass('radio-item');
    $('input:checked').parent().addClass('checked');

    $('.checkbox a.check').click(function (event) {
        event.preventDefault();

        if ($(this).parent().find('input:checkbox').is(':checked')) {
            $(this).parent().removeClass('checked');
            $(this).parent().find('input:checkbox').removeAttr('checked');
        }
        else {
            $(this).parent().addClass('checked');
            $(this).parent().find('input:checkbox').attr('checked', 'checked');
        }
    });

    $('ul.form .radiobutton a.radio').click(function (event) {
        event.preventDefault();

        $(this).closest('.radiobutton').find('.checked').removeClass('checked');
        $(this).closest('.radiobutton').find('input:radio').removeAttr('checked');

        $(this).parent().addClass('checked');
        $(this).parent().find('input:radio').attr('checked', 'checked');
    });


    /*================================================
    My Account
    ================================================*/
    $('#content.account table.form td[width="35%"]').addClass('label');
    $('#content.account table.form td[width="36%"]').addClass('label');
    $('#content.account table.form td[width="65%"]').addClass('input');

    $('#content.account table.form td.label').removeAttr('width').removeAttr('align');
    $('#content.account table.form td.input').removeAttr('width');

    $('#content.account table.form td.input input[type="text"], #content.account table.form td.input input[type="password"]').addClass('text');
    $('#content.account table.form td input:checkbox').parent().addClass('checkbox');
    $('#content.account table.form td input:radio').parent().addClass('radiobutton');


    //$('#content.account table.form .checkbox a.check').click(function (event) {
    //	event.preventDefault();
    //	
    ////	$(this).parent('.checkbox').removeClass('checked');
    //	$(this).parent('.checkbox').find('input:checkbox').removeAttr('checked');

    ////	$(this).parent().addClass('checked');
    //	$(this).parent().find('input:checkbox').attr('checked', 'checked');			
    //});



    /*================================================
    Search Results
    ================================================*/
    $('#content.search-results .listing .listing-item').hover(
function () { $(this).addClass('hover'); },
function () {
    $(this).removeClass('hover');
});


    /*================================================
    Advanced Product Search
    ================================================*/
    $('#content.advanced-search div.advanced-results #results .listing .listing-item:nth-child(2n)').addClass('row-end');

    $('#content.advanced-search div.advanced-results #filter h3').click(function () {
        $(this).toggleClass('active').next('.toggle-content').slideToggle(500);
    });

    $('#content.advanced-search div.advanced-results #filter h3').hover(
function () { $(this).addClass('hover'); },
function () {
    $(this).removeClass('hover');
});


    /*================================================
    News Landing
    ================================================*/
    $('#content.news-landing .listing .listing-item').hover(
function () { $(this).addClass('hover'); },
function () {
    $(this).removeClass('hover');
});


    /*================================================
    First/Last Items
    ================================================*/
    /*---- UL ----*/
    $('ul li:first-child').addClass('first');
    $('ul li:last-child').addClass('last');

    /*---- Home Feature ----*/
    $('div#content.home div#features div.feature:last').addClass('last');


    /*================================================
    Contact Nav Positioning Fix for IE
    ================================================*/
    var nameBoxWidth = 0;
    //var contactNavWidth = 270;
	var contactNavWidth = 274;

    if ($.browser.msie && $.browser.version == 7) {
        nameBoxWidth = $('#header ul.nav.contact li.account').width();
        //alert(nameBoxWidth);
        $('#header ul.nav.contact').width(contactNavWidth + nameBoxWidth);
    }

   
    
	
	

    $(".listing-item.row-end").after('<div style="width:100%; float:left;"></div>');

    $("#related-products .rp-listing-item:last-child").css({"marginRight": "0"});
	


});

	
