﻿$.fn.initProductDetail = function() {
    $('div.detailImg').each(function(i){
        $(this).hide();
        if(i == 0){
            // show first element
            $(this).show();
        }
    });
    $('div.conPreview').find('a').each(function(i){
        $(this).removeClass('selected');
        if(i == 0){
            // select first icon
            $(this).addClass('selected');
        }
    });
    $('div.conProductDesc').each(function(i){
        $(this).hide();
        if(i == 0){
            // show first element
            $(this).show();
        }
    });
    $('#tab1').show();
    $('#tab2').hide();
};

$(document).ready(function() {

    //    $('a.linkArrowTop').click(function(e){
    //		e.preventDefault();
    //		$('html').scrollTo(0, 800);
    //		return false;
    //	});

    // init images and videos on product detail
    $(this).initProductDetail();

    $('div.conPreview').find('a').click(function() {
        $('div.detailImg').each(function() {
            // hide all images
            $(this).hide();
        });
        $('div.conPreview').find('a').each(function() {
            // deselect all selected icons
            $(this).removeClass('selected');
        });
        $('div.conProductDesc').each(function(i) {
            // hide all descriptions
            $(this).hide();
        });

        // show selected elements
        $(this).addClass('selected');
        $('#img-' + this.title).show();
        $('#imgDescr-' + this.title).show();
    });

    $('#tabLink1').find('a').click(function() {
        // init images and videos on product detail
        $(this).initProductDetail();

        $(this).addClass('active');
        $('#tabLink2').find('a').removeClass('active');
        $('#tab1').show();
        $('#tab2').hide();
    });
    $('#tabLink2').find('a').click(function() {
        $(this).addClass('active');
        $('#tabLink1').find('a').removeClass('active');
        $('#tab1').hide();
        $('#tab2').show();
    });

    $('div.product').hide();
    $('div.conTitleBg').click(function(e) {
        //e.preventDefault();
        $(this).next('div.product').toggle(400);
    });
});


