// Wishlist Validation

$().ready(function() {
	
	// validate signup form on keyup and submit
	$("#addToWishingListForm").validate({
		rules:
		{
			WishingListCount: 
			{
				required: true,
				min: 1
			}
		},
		messages:
		{
			WishingListCount: "Indtast minimum &eacute;n"
		}
	});
	
	$("#addToBasketForm").validate({
		rules:
		{
			quantity: 
			{
				required: true,
				min: 1
			}
		},
		messages:
		{
			quantity: "Indtast minimum &eacute;n"
		}
	});
});

// Tooltip

	jQuery(document).ready(function() {
		jQuery('a.showmessage').click(function()
		{
			tooltip.show("<span class='indent'>Vare tilf&oslash;jet til kurv</span>");
		})
	});
	
	jQuery(document).ready(function() {
		jQuery('a.showmessagewish').click(function()
		{
			tooltip.show("<span class='indent'>Vare tilf&oslash;jet til &oslash;nskeliste</span>");
		})
	});
	
	
// Flash Video player + Jquery Cycle plugin 

//$(function() {
//    //checkImages();
//    cycleImages();
//});

// hide images if 404 not found
//function checkImages()
//{
//    for (var i = 0; i < $('#nav img').length; i++) 
//       if ($('#nav img')[i].complete && (typeof $('#nav img')[i].naturalWidth != 'undefined' && $('#nav img')[i].naturalWidth == 0))
//            $('#nav img:eq(' + i + ')').css('display', 'none');
//}

function cycleImages(startIndex)
{
    if ($('#slideProd img').length > 1)
    {
        $('#slideProd').cycle({
	        fx:     'fade',
	        speed:  '1000',
	        timeout: '0',
	        pager:  '#nav',
	        pagerEvent: 'mouseover',
	        pagerAnchorBuilder: function(idx, slide){
	        // return sel string for existing anchor
	            return '#nav li:eq(' + (idx) + ') a';
            }
        });
        if (startIndex == null || startIndex < 0)
            startIndex = 0;
        $('#slideProd').cycle(startIndex);
    }
}

// html code for rollback (when removing video player)
var slideInnerHtml;

function playerReady(thePlayer)
{
    $('#player')[0].addModelListener('STATE', 'stopVideo');
}

function playVideo(url)
{
    if ($('#player').length == 0)
    {
        var s1 = new SWFObject('files/system/video/player.swf','player','450','420','9');
        s1.addParam('allowfullscreen','true');
        s1.addParam('allowscriptaccess','always');
        s1.addParam('flashvars','file=' + url + '&autostart=true');
        slideInnerHtml = $('#slideProd')[0].innerHTML
        s1.write('slideProd');
    }
}

function stopVideo(state)
{
    if ($('#player').length != 0 && (state.newstate == 'COMPLETED' || state.newstate == 'IDLE'))
    {
        showSlide(null);
    }
}

function showSlide(image)
{
    if ($('#player').length != 0)
    {
        $('#slideProd')[0].innerHTML = slideInnerHtml;
        cycleImages($('#nav img').index(image));
    }
}


// thumbs

//            if ($('#nav li').length == 1)
//            {
//                ///$('#miscBot p').text('Se billedet:');
//                $('#miscBot').hide();
//            }



// start slideshow cycle

//      cycleImages();


// Wishlist and basket control


function addToBasket(formId)
{
    $("#" + formId).submit();
	//$("#" + "<!--@Ecom:Product.ID-->").submit();
}

function addToWishingList(productID)
{
    document.addToWishingListForm.productID.value = productID;
    document.addToWishingListForm.addToWishingListCount.value = document.addToWishingListForm.WishingListCount.value;
    
	window.location = window.location.toString() + "&WLProductID=" + document.addToWishingListForm.productID.value + "&WLProductLanguageID=" + document.addToWishingListForm.productLanguageID.value + "&WLProductVariantID=" + document.addToWishingListForm.productVariantID.value + "&WLCount=" + document.addToWishingListForm.addToWishingListCount.value;
	
	//document.addToWishingListForm.submit();
}

function wishingListQuantityPressed(control)
{
    var reg = /^[0-9]{1,3}$/;
    if ((control.value != "") && (control.value.toString().match(reg)))
    {
        $("#wishingListQuantityWarning_" + control.form.id).css("display", "none");
        return true;
    }
    else
    {
    	$("#wishingListQuantityWarning_" + control.form.id).css("display", "");
    	return false;
    }
}


