﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
    //loads popup only if it is disabled
    if(popupStatus==0){
        $("#backgroundPopup").css({
            "opacity": "0.7"
        });
        $("#backgroundPopup").fadeIn("slow");
        $("#popupContact").fadeIn("slow");
        popupStatus = 1;
    }
}

//disabling popup with jQuery magic!
function disablePopup(){
    //disables popup only if it is enabled
    if(popupStatus==1){
        $("#backgroundPopup").fadeOut("slow");
        $("#popupContact").fadeOut("slow");
        popupStatus = 0;
    }
}

//centering popup
function centerPopup(){
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popupContact").height();
    var popupWidth = $("#popupContact").width();
    //centering
    $("#popupContact").css({
        "position": "absolute",
        "top": windowHeight/2-popupHeight/2,
        "left": windowWidth/2-popupWidth/2
    });
    //only need force for IE6
	
    $("#backgroundPopup").css({
        "height": windowHeight
    });
	
}

function changeVideo(video){    
    if(video == 1){
        src = '<object width="420" height="345"><param name="movie" value="http://www.youtube.com/v/Mg_Hu7eq4Yo?version=3&amp;rel=0&amp;autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Mg_Hu7eq4Yo?version=3&amp;rel=0&amp;autoplay=1" type="application/x-shockwave-flash" width="420" height="345" allowscriptaccess="always" allowfullscreen="true"></embed></object>';        
        img = "thimoty";
    }else if(video == 2){
        src = '<object width="420" height="345"><param name="movie" value="http://www.youtube.com/v/EyiFMNPrg6Q?version=3&amp;autoplay=1&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/EyiFMNPrg6Q?version=3&amp;rel=0&amp;autoplay=1" type="application/x-shockwave-flash" width="420" height="345" allowscriptaccess="always" allowfullscreen="true"></embed></object>';        
        img = "johnny";
    }else if(video == 3){
        src = '<object width="420" height="345"><param name="movie" value="http://www.youtube.com/v/csxPN_lNYwg?version=3&amp;rel=0&amp;autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/csxPN_lNYwg?version=3&amp;rel=0&amp;autoplay=1" type="application/x-shockwave-flash" width="420" height="345" allowscriptaccess="always" allowfullscreen="true"></embed></object>';        
        img = "point-of-sale-system";
    }    
    $(".videocontainer .topvideo .float-right img").each(function () {        
        if($(this).attr('id') == 'video'+video){$(this).attr('src', '/wp-content/themes/buckstore/images/'+img+'.jpg');} 
        else {
            srcvar = $(this).attr('src');             
            if(srcvar.search('-np.jpg') == -1){
                $(this).attr('src', srcvar.replace('.jpg','-np.jpg'));
            }
        }
    });    
    $(".videocontainer .topvideo .float-left").html(src);
    
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){	
    //LOADING POPUP
    //Click the button event!
    $("#video").click(function(){		
        //document.getElementById("popupContactContent").innerHTML="<p id='contactArea'>	<iframe width='480' height='390' src='http://www.youtube.com/embed/Mg_Hu7eq4Yo?rel=0&autoplay=1' frameborder='0' allowfullscreen></iframe></p>";
        //<object width="480" height="390"><param name="movie" value="http://www.youtube.com/v/Mg_Hu7eq4Yo?version=3&amp;rel=0&amp;autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Mg_Hu7eq4Yo?version=3&amp;rel=0&amp;autoplay=1" type="application/x-shockwave-flash" width="480" height="390" allowscriptaccess="always" allowfullscreen="true"></embed></object>
        variable ='<div class="videocontainer">\
                        <div class="topvideo">\
                            <div class="float-left"> \
                            <object width="420" height="345">\
                                <param name="movie" value="http://www.youtube.com/v/Mg_Hu7eq4Yo?version=3&amp;rel=0&amp;autoplay=1"></param>\
                                <param name="allowFullScreen" value="true"></param>\
                                <param name="allowscriptaccess" value="always"></param>\
                                <embed src="http://www.youtube.com/v/Mg_Hu7eq4Yo?version=3&amp;rel=0&amp;autoplay=1" type="application/x-shockwave-flash" width="420" height="345" allowscriptaccess="always" allowfullscreen="true"></embed>\
                            </object>\
                            </div>\
                            <div class="float-right"> \
                                <a onclick="changeVideo(1)" class="hand"><img id="video1" src="wp-content/themes/buckstore/images/thimoty.jpg"/></a>\
                                   <a onclick="changeVideo(1)" class="hand">Timothy Dwight</a> \
                                   <span>Dollar Store Center</span>\
                                <a onclick="changeVideo(2)" class="hand"><img id="video2" src="wp-content/themes/buckstore/images/johnny-np.jpg"/></a>\
                                   <a onclick="changeVideo(2)" class="hand">Johnny Richards</a> \
                                   <span>Dollar Store House</span>\
                            </div>\
                        </div>\
                    <div class="bottomvideotext">\
                       <div class="float-left">\
                          <p><span class="strong">Buckstore Inc.</span> has helped open and develop over 4,000 Stores in 15 years Nationwide and Overseas. Visit our <a href="/dollar-store-buckstore-testimonials/">Testimonials</a> section for more store references. Build-out Release Forms from our crews. Awards, and information about our company.</p>\
                       </div>\
                       <div class="float-right">\
                            <p><span>Share</span> \
                            <a onclick="gtp(\'www.facebook.com\',\'/sharer.php?u=http://www.buckstore.com/dollar-store-buckstore-testimonials/&t=Dollar Store Testimonials\')" class="hand"><img src="wp-content/themes/buckstore/images/facebook.jpg"/></a> \
                            <a onclick="gtp(\'twitter.com\',\'/home?status=Currently reading http://www.buckstore.com/dollar-store-buckstore-testimonials/&title=Dollar+Store+Testimonials\')" class="hand"><img src="wp-content/themes/buckstore/images/twitter.jpg"/></a></p>\
                       </div>\
                    </div>\
                 </div>';
        document.getElementById("popupContactContent").innerHTML = variable;
        
        $( "#dialog:ui-dialog" ).dialog( "destroy" );
	
		$( "#popupContactContent" ).dialog({
			height: 450,
                        width: 610,
			modal: true,
                        close: function(event, ui) {  document.getElementById("popupContactContent").innerHTML=""; }
		});
        //centering with css
        //centerPopup();
        //load popup
        //loadPopup();
    });
	// OPEN POINT OF SALE POPUP
	$(".video-pos, .watch_video").click(function(){		       
        variable ='<div class="videocontainer">\
                        <div class="topvideo">\
                            <div class="float-left"> \
                            <object width="420" height="345">\
                                <param name="movie" value="http://www.youtube.com/v/csxPN_lNYwg?version=3&amp;rel=0&amp;autoplay=1"></param>\
                                <param name="allowFullScreen" value="true"></param>\
                                <param name="allowscriptaccess" value="always"></param>\
                                <embed src="http://www.youtube.com/v/csxPN_lNYwg?version=3&amp;rel=0&amp;autoplay=1" type="application/x-shockwave-flash" width="420" height="345" allowscriptaccess="always" allowfullscreen="true"></embed>\
                            </object>\
                            </div>\
                            <div class="float-right"> \
                                <a onclick="changeVideo(3)" class="hand"><img id="video3" src="/wp-content/themes/buckstore/images/point-of-sale-system.jpg"/></a>\
                                   <a onclick="changeVideo(3)" class="hand">Point of Sale System</a> \
                            </div>\
                        </div>\
                    <div class="bottomvideotext">\
                       <div class="float-left">\
                          <p><span class="strong">Buckstore Inc.</span> has helped open and develop over 4,000 Stores in 15 years Nationwide and Overseas. Visit our <a href="/dollar-store-buckstore-testimonials/">Testimonials</a> section for more store references. Build-out Release Forms from our crews. Awards, and information about our company.</p>\
                       </div>\
                       <div class="float-right">\
                            <p><span>Share</span> \
                            <a onclick="gtp(\'www.facebook.com\',\'/sharer.php?u=http://www.buckstore.com/point-of-sales-systems/&t=Point of Sales Systems\')" class="hand"><img src="/wp-content/themes/buckstore/images/facebook.jpg"/></a> \
                            <a onclick="gtp(\'twitter.com\',\'/home?status=Currently reading http://www.buckstore.com/point-of-sales-systems/&title=Point+of+Sales+Systems\')" class="hand"><img src="/wp-content/themes/buckstore/images/twitter.jpg"/></a></p>\
                       </div>\
                    </div>\
                 </div>';
        document.getElementById("popupContactContent").innerHTML = variable;        
        $( "#dialog:ui-dialog" ).dialog( "destroy" );
		$( "#popupContactContent" ).dialog({
			height: 450,
            width: 610,
			modal: true,
            close: function(event, ui) {  document.getElementById("popupContactContent").innerHTML=""; }
		});
    });
	
    //CLOSING POPUP
    //Click the x event!
    $("#popupContactClose").click(function(){
        disablePopup();
        document.getElementById("popupContactContent").innerHTML="";
    });	
    //Click out event!
    $("#backgroundPopup").click(function(){
        disablePopup();
        document.getElementById("popupContactContent").innerHTML="";
    });
    //Press Escape event!
    $(document).keypress(function(e){
        if(e.keyCode==27 && popupStatus==1){
            disablePopup();
            document.getElementById("popupContactContent").innerHTML="";
        }
    });

});
