﻿(function($) {
    $(document).ready(function() {
        var aNewsletter = $('.btn-hide-show a'); //Show/Hide link
        var divSubscribe = $('.ipad-wrapper'); //Subscription container
        if (divSubscribe.length != 0) {  //DOM Exists
            //Did the user hide the div.
            var stateCookie = $.cookie('expanded_' + divSubscribe.attr('class'));
            //alert(stateCookie);
            if (stateCookie == null) {   //No he didn't
                divSubscribe.show();
                aNewsletter.removeClass('show');
//                aNewsletter.parent().toggleClass('show');
            }
            else {
                divSubscribe.hide();
                aNewsletter.addClass('show');
                //aNewsletter.parent().toggleClass('show');
            }

            aNewsletter.click(function(e) {
                divSubscribe.slideToggle('slow', function() {
                    //divNewsletter = aNewsletter.parent(); //Div with the background image                    					
                    aNewsletter.toggleClass('show');
                    //Set the cooke as desired
                    var divSubscribeClass = divSubscribe.css('display');
                    if (divSubscribeClass == 'none') {   //User does not bother about our newsletters :-)
                        //Set the cookie to hide the div
                        //alert("1");
                        $.cookie('expanded_' + divSubscribe.attr('class'), true, { path: '/' });
                        //alert($.cookie('expanded_' + divSubscribe.attr('class')));
                    } else {    //Expand on all pages
                        //alert("2");
                        $.cookie('expanded_' + divSubscribe.attr('class'), null, { path: '/' });
                        //alert($.cookie('expanded_' + divSubscribe.attr('class')));
                    }
                });
                return false;
            });
        }
    });
})(jQuery);
